1 |
|
---|
2 | /** This character denotes the end of file */
|
---|
3 | public static final int YYEOF = -1;
|
---|
4 |
|
---|
5 | /** initial size of the lookahead buffer */
|
---|
6 | --- private static final int ZZ_BUFFERSIZE = ...;
|
---|
7 |
|
---|
8 | /** lexical states */
|
---|
9 | --- lexical states, charmap
|
---|
10 |
|
---|
11 | /* error codes */
|
---|
12 | private static final int ZZ_UNKNOWN_ERROR = 0;
|
---|
13 | private static final int ZZ_NO_MATCH = 1;
|
---|
14 | private static final int ZZ_PUSHBACK_2BIG = 2;
|
---|
15 |
|
---|
16 | /* error messages for the codes above */
|
---|
17 | private static final String ZZ_ERROR_MSG[] = {
|
---|
18 | "Unkown internal scanner error",
|
---|
19 | "Error: could not match input",
|
---|
20 | "Error: pushback value was too large"
|
---|
21 | };
|
---|
22 |
|
---|
23 | --- isFinal list
|
---|
24 | /** the input device */
|
---|
25 | private java.io.Reader zzReader;
|
---|
26 |
|
---|
27 | /** the current state of the DFA */
|
---|
28 | private int zzState;
|
---|
29 |
|
---|
30 | /** the current lexical state */
|
---|
31 | private int zzLexicalState = YYINITIAL;
|
---|
32 |
|
---|
33 | /** this buffer contains the current text to be matched and is
|
---|
34 | the source of the yytext() string */
|
---|
35 | private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
|
---|
36 |
|
---|
37 | /** the textposition at the last accepting state */
|
---|
38 | private int zzMarkedPos;
|
---|
39 |
|
---|
40 | /** the current text position in the buffer */
|
---|
41 | private int zzCurrentPos;
|
---|
42 |
|
---|
43 | /** startRead marks the beginning of the yytext() string in the buffer */
|
---|
44 | private int zzStartRead;
|
---|
45 |
|
---|
46 | /** endRead marks the last character in the buffer, that has been read
|
---|
47 | from input */
|
---|
48 | private int zzEndRead;
|
---|
49 |
|
---|
50 | /** number of newlines encountered up to the start of the matched text */
|
---|
51 | private int yyline;
|
---|
52 |
|
---|
53 | /** the number of characters up to the start of the matched text */
|
---|
54 | private int yychar;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * the number of characters from the last newline up to the start of the
|
---|
58 | * matched text
|
---|
59 | */
|
---|
60 | private int yycolumn;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
---|
64 | */
|
---|
65 | private boolean zzAtBOL = true;
|
---|
66 |
|
---|
67 | /** zzAtEOF == true <=> the scanner is at the EOF */
|
---|
68 | private boolean zzAtEOF;
|
---|
69 |
|
---|
70 | /** denotes if the user-EOF-code has already been executed */
|
---|
71 | private boolean zzEOFDone;
|
---|
72 |
|
---|
73 | --- user class code
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Creates a new scanner
|
---|
77 | * There is also a java.io.InputStream version of this constructor.
|
---|
78 | *
|
---|
79 | * @param in the java.io.Reader to read input from.
|
---|
80 | */
|
---|
81 | --- constructor declaration
|
---|
82 |
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Refills the input buffer.
|
---|
86 | *
|
---|
87 | * @return <code>false</code>, iff there was new input.
|
---|
88 | *
|
---|
89 | * @exception java.io.IOException if any I/O-Error occurs
|
---|
90 | */
|
---|
91 | private boolean zzRefill() throws java.io.IOException {
|
---|
92 |
|
---|
93 | /* first: make room (if you can) */
|
---|
94 | if (zzStartRead > 0) {
|
---|
95 | System.arraycopy(zzBuffer, zzStartRead,
|
---|
96 | zzBuffer, 0,
|
---|
97 | zzEndRead-zzStartRead);
|
---|
98 |
|
---|
99 | /* translate stored positions */
|
---|
100 | zzEndRead-= zzStartRead;
|
---|
101 | zzCurrentPos-= zzStartRead;
|
---|
102 | zzMarkedPos-= zzStartRead;
|
---|
103 | zzStartRead = 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* is the buffer big enough? */
|
---|
107 | if (zzCurrentPos >= zzBuffer.length) {
|
---|
108 | /* if not: blow it up */
|
---|
109 | char newBuffer[] = new char[zzCurrentPos*2];
|
---|
110 | System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
|
---|
111 | zzBuffer = newBuffer;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* finally: fill the buffer with new input */
|
---|
115 | int numRead = zzReader.read(zzBuffer, zzEndRead,
|
---|
116 | zzBuffer.length-zzEndRead);
|
---|
117 |
|
---|
118 | if (numRead > 0) {
|
---|
119 | zzEndRead+= numRead;
|
---|
120 | return false;
|
---|
121 | }
|
---|
122 | // unlikely but not impossible: read 0 characters, but not at end of stream
|
---|
123 | if (numRead == 0) {
|
---|
124 | int c = zzReader.read();
|
---|
125 | if (c == -1) {
|
---|
126 | return true;
|
---|
127 | } else {
|
---|
128 | zzBuffer[zzEndRead++] = (char) c;
|
---|
129 | return false;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | // numRead < 0
|
---|
134 | return true;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Closes the input stream.
|
---|
140 | */
|
---|
141 | public final void yyclose() throws java.io.IOException {
|
---|
142 | zzAtEOF = true; /* indicate end of file */
|
---|
143 | zzEndRead = zzStartRead; /* invalidate buffer */
|
---|
144 |
|
---|
145 | if (zzReader != null)
|
---|
146 | zzReader.close();
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Resets the scanner to read from a new input stream.
|
---|
152 | * Does not close the old reader.
|
---|
153 | *
|
---|
154 | * All internal variables are reset, the old input stream
|
---|
155 | * <b>cannot</b> be reused (internal buffer is discarded and lost).
|
---|
156 | * Lexical state is set to <tt>ZZ_INITIAL</tt>.
|
---|
157 | *
|
---|
158 | * @param reader the new input stream
|
---|
159 | */
|
---|
160 | public final void yyreset(java.io.Reader reader) {
|
---|
161 | zzReader = reader;
|
---|
162 | zzAtBOL = true;
|
---|
163 | zzAtEOF = false;
|
---|
164 | zzEOFDone = false;
|
---|
165 | zzEndRead = zzStartRead = 0;
|
---|
166 | zzCurrentPos = zzMarkedPos = 0;
|
---|
167 | yyline = yychar = yycolumn = 0;
|
---|
168 | zzLexicalState = YYINITIAL;
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Returns the current lexical state.
|
---|
174 | */
|
---|
175 | public final int yystate() {
|
---|
176 | return zzLexicalState;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Enters a new lexical state
|
---|
182 | *
|
---|
183 | * @param newState the new lexical state
|
---|
184 | */
|
---|
185 | public final void yybegin(int newState) {
|
---|
186 | zzLexicalState = newState;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Returns the text matched by the current regular expression.
|
---|
192 | */
|
---|
193 | public final String yytext() {
|
---|
194 | return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Returns the character at position <tt>pos</tt> from the
|
---|
200 | * matched text.
|
---|
201 | *
|
---|
202 | * It is equivalent to yytext().charAt(pos), but faster
|
---|
203 | *
|
---|
204 | * @param pos the position of the character to fetch.
|
---|
205 | * A value from 0 to yylength()-1.
|
---|
206 | *
|
---|
207 | * @return the character at position pos
|
---|
208 | */
|
---|
209 | public final char yycharat(int pos) {
|
---|
210 | return zzBuffer[zzStartRead+pos];
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Returns the length of the matched text region.
|
---|
216 | */
|
---|
217 | public final int yylength() {
|
---|
218 | return zzMarkedPos-zzStartRead;
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Reports an error that occured while scanning.
|
---|
224 | *
|
---|
225 | * In a wellformed scanner (no or only correct usage of
|
---|
226 | * yypushback(int) and a match-all fallback rule) this method
|
---|
227 | * will only be called with things that "Can't Possibly Happen".
|
---|
228 | * If this method is called, something is seriously wrong
|
---|
229 | * (e.g. a JFlex bug producing a faulty scanner etc.).
|
---|
230 | *
|
---|
231 | * Usual syntax/scanner level error handling should be done
|
---|
232 | * in error fallback rules.
|
---|
233 | *
|
---|
234 | * @param errorCode the code of the errormessage to display
|
---|
235 | */
|
---|
236 | --- zzScanError declaration
|
---|
237 | String message;
|
---|
238 | try {
|
---|
239 | message = ZZ_ERROR_MSG[errorCode];
|
---|
240 | }
|
---|
241 | catch (ArrayIndexOutOfBoundsException e) {
|
---|
242 | message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
---|
243 | }
|
---|
244 |
|
---|
245 | --- throws clause
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Pushes the specified amount of characters back into the input stream.
|
---|
251 | *
|
---|
252 | * They will be read again by then next call of the scanning method
|
---|
253 | *
|
---|
254 | * @param number the number of characters to be read again.
|
---|
255 | * This number must not be greater than yylength()!
|
---|
256 | */
|
---|
257 | --- yypushback decl (contains zzScanError exception)
|
---|
258 | if ( number > yylength() )
|
---|
259 | zzScanError(ZZ_PUSHBACK_2BIG);
|
---|
260 |
|
---|
261 | zzMarkedPos -= number;
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | --- zzDoEOF
|
---|
266 | /**
|
---|
267 | * Resumes scanning until the next regular expression is matched,
|
---|
268 | * the end of input is encountered or an I/O-Error occurs.
|
---|
269 | *
|
---|
270 | * @return the next token
|
---|
271 | * @exception java.io.IOException if any I/O-Error occurs
|
---|
272 | */
|
---|
273 | --- yylex declaration
|
---|
274 | int zzInput;
|
---|
275 | int zzAction;
|
---|
276 |
|
---|
277 | // cached fields:
|
---|
278 | int zzCurrentPosL;
|
---|
279 | int zzMarkedPosL;
|
---|
280 | int zzEndReadL = zzEndRead;
|
---|
281 | char [] zzBufferL = zzBuffer;
|
---|
282 | char [] zzCMapL = ZZ_CMAP;
|
---|
283 |
|
---|
284 | --- local declarations
|
---|
285 |
|
---|
286 | while (true) {
|
---|
287 | zzMarkedPosL = zzMarkedPos;
|
---|
288 |
|
---|
289 | --- start admin (line, char, col count)
|
---|
290 | zzAction = -1;
|
---|
291 |
|
---|
292 | zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
|
---|
293 |
|
---|
294 | --- start admin (lexstate etc)
|
---|
295 |
|
---|
296 | zzForAction: {
|
---|
297 | while (true) {
|
---|
298 |
|
---|
299 | --- next input, line, col, char count, next transition, isFinal action
|
---|
300 | zzAction = zzState;
|
---|
301 | zzMarkedPosL = zzCurrentPosL;
|
---|
302 | --- line count update
|
---|
303 | }
|
---|
304 |
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | // store back cached position
|
---|
309 | zzMarkedPos = zzMarkedPosL;
|
---|
310 | --- char count update
|
---|
311 |
|
---|
312 | --- actions
|
---|
313 | default:
|
---|
314 | if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
---|
315 | zzAtEOF = true;
|
---|
316 | --- eofvalue
|
---|
317 | }
|
---|
318 | else {
|
---|
319 | --- no match
|
---|
320 | }
|
---|
321 | }
|
---|
322 | }
|
---|
323 | }
|
---|
324 |
|
---|
325 | --- main
|
---|
326 |
|
---|
327 | }
|
---|