@@ -11,14 +11,15 @@ section presents a part of the specification for the Java language.
11
11
12
12
The example does not describe the whole lexical structure of Java programs,
13
13
but only a small and simplified part of it:
14
+
14
15
- some keywords,
15
16
- some operators,
16
- - comments
17
+ - comments
17
18
- and only two kinds of literals.
18
19
19
- It also shows how to interface with the LALR parser generator CUP [ @CUP ]
20
+ It also shows how to interface with the LALR parser generator CUP [ @CUP ]
20
21
and therefore uses a class ` sym ` (generated by CUP), where integer constants
21
- for the terminal tokens of the CUP grammar are declared.
22
+ for the terminal tokens of the CUP grammar are declared.
22
23
23
24
You can find this example in ` examples/cup-java-minijava ` .
24
25
@@ -29,7 +30,7 @@ interface with the JFlex scanner). Both specifications adhere to the Java
29
30
Language Specification [ @LangSpec ] .
30
31
31
32
In ` examples/standalone ` , you can find a small standalone scanner that
32
- doesn’t need other dependencies or tools like CUP to give you working code.
33
+ doesn’t need other dependencies or tools like CUP to give you working code.
33
34
34
35
35
36
```
@@ -85,9 +86,9 @@ doesn’t need other dependencies or tools like CUP to give you working code.
85
86
<YYINITIAL> "break" { return symbol(sym.BREAK); }
86
87
87
88
<YYINITIAL> {
88
- /* identifiers */
89
+ /* identifiers */
89
90
{Identifier} { return symbol(sym.IDENTIFIER); }
90
-
91
+
91
92
/* literals */
92
93
{DecIntegerLiteral} { return symbol(sym.INTEGER_LITERAL); }
93
94
\" { string.setLength(0); yybegin(STRING); }
@@ -99,22 +100,22 @@ doesn’t need other dependencies or tools like CUP to give you working code.
99
100
100
101
/* comments */
101
102
{Comment} { /* ignore */ }
102
-
103
+
103
104
/* whitespace */
104
105
{WhiteSpace} { /* ignore */ }
105
106
}
106
107
107
108
<STRING> {
108
- \" { yybegin(YYINITIAL);
109
- return symbol(sym.STRING_LITERAL,
109
+ \" { yybegin(YYINITIAL);
110
+ return symbol(sym.STRING_LITERAL,
110
111
string.toString()); }
111
112
[^\n\r\"\\]+ { string.append( yytext() ); }
112
113
\\t { string.append('\t'); }
113
114
\\n { string.append('\n'); }
114
115
115
116
\\r { string.append('\r'); }
116
117
\\\" { string.append('\"'); }
117
- \\ { string.append('\\'); }
118
+ \\\\ { string.append('\\'); }
118
119
}
119
120
120
121
/* error fallback */
0 commit comments