Skip to content

Commit

Permalink
manual: fix string escapes in example (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsf37 authored Apr 17, 2023
1 parent ffb61f1 commit 4c942c5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions docs/md/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ section presents a part of the specification for the Java language.

The example does not describe the whole lexical structure of Java programs,
but only a small and simplified part of it:

- some keywords,
- some operators,
- comments
- comments
- and only two kinds of literals.

It also shows how to interface with the LALR parser generator CUP [@CUP]
It also shows how to interface with the LALR parser generator CUP [@CUP]
and therefore uses a class `sym` (generated by CUP), where integer constants
for the terminal tokens of the CUP grammar are declared.
for the terminal tokens of the CUP grammar are declared.

You can find this example in `examples/cup-java-minijava`.

Expand All @@ -29,7 +30,7 @@ interface with the JFlex scanner). Both specifications adhere to the Java
Language Specification [@LangSpec].

In `examples/standalone`, you can find a small standalone scanner that
doesn’t need other dependencies or tools like CUP to give you working code.
doesn’t need other dependencies or tools like CUP to give you working code.


```
Expand Down Expand Up @@ -85,9 +86,9 @@ doesn’t need other dependencies or tools like CUP to give you working code.
<YYINITIAL> "break" { return symbol(sym.BREAK); }
<YYINITIAL> {
/* identifiers */
/* identifiers */
{Identifier} { return symbol(sym.IDENTIFIER); }
/* literals */
{DecIntegerLiteral} { return symbol(sym.INTEGER_LITERAL); }
\" { string.setLength(0); yybegin(STRING); }
Expand All @@ -99,22 +100,22 @@ doesn’t need other dependencies or tools like CUP to give you working code.
/* comments */
{Comment} { /* ignore */ }
/* whitespace */
{WhiteSpace} { /* ignore */ }
}
<STRING> {
\" { yybegin(YYINITIAL);
return symbol(sym.STRING_LITERAL,
\" { yybegin(YYINITIAL);
return symbol(sym.STRING_LITERAL,
string.toString()); }
[^\n\r\"\\]+ { string.append( yytext() ); }
\\t { string.append('\t'); }
\\n { string.append('\n'); }
\\r { string.append('\r'); }
\\\" { string.append('\"'); }
\\ { string.append('\\'); }
\\\\ { string.append('\\'); }
}
/* error fallback */
Expand Down

0 comments on commit 4c942c5

Please sign in to comment.