From 4c942c5ad702199be7bea2876a01c84ef6c1fd23 Mon Sep 17 00:00:00 2001 From: Gerwin Klein Date: Mon, 17 Apr 2023 16:17:15 +1000 Subject: [PATCH] manual: fix string escapes in example (#1091) --- docs/md/example.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/md/example.md b/docs/md/example.md index 92ed73000..a1b30ba24 100644 --- a/docs/md/example.md +++ b/docs/md/example.md @@ -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`. @@ -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. ``` @@ -85,9 +86,9 @@ doesn’t need other dependencies or tools like CUP to give you working code. "break" { return symbol(sym.BREAK); } { - /* identifiers */ + /* identifiers */ {Identifier} { return symbol(sym.IDENTIFIER); } - + /* literals */ {DecIntegerLiteral} { return symbol(sym.INTEGER_LITERAL); } \" { string.setLength(0); yybegin(STRING); } @@ -99,14 +100,14 @@ doesn’t need other dependencies or tools like CUP to give you working code. /* comments */ {Comment} { /* ignore */ } - + /* whitespace */ {WhiteSpace} { /* ignore */ } } { - \" { 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'); } @@ -114,7 +115,7 @@ doesn’t need other dependencies or tools like CUP to give you working code. \\r { string.append('\r'); } \\\" { string.append('\"'); } - \\ { string.append('\\'); } + \\\\ { string.append('\\'); } } /* error fallback */