KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestLexer03


1 /* The following code was generated by JFlex 1.4_5 on 12/12/03 12:48 PM */
2
3
4 import ro.infoiasi.donald.compiler.cfg.*;
5 import ro.infoiasi.donald.compiler.parser.*;
6
7
8 /**
9  * This class is a scanner generated by
10  * <a HREF="http://www.jflex.de/">JFlex</a> 1.4_5
11  * on 12/12/03 12:48 PM from the specification file
12  * <tt>TestLexer03.flex</tt>
13  */

14 public class TestLexer03 implements Lexer {
15
16   /** This character denotes the end of file */
17   public static final int YYEOF = -1;
18
19   /** initial size of the lookahead buffer */
20   private static final int YY_BUFFERSIZE = 16384;
21
22   /** lexical states */
23   public static final int YYINITIAL = 0;
24
25   /**
26    * Translates characters to character classes
27    */

28   private static final char [] yycmap = {
29      5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 2, 0, 3, 1, 5, 5,
30      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
31      3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0,
32      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 6, 0, 0,
33      0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
34      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 4,
35      0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
36      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 5
37   };
38
39   /**
40    * Translates DFA states to action switch labels.
41    */

42   private static final int [] YY_ACTION = yy_unpack_YY_ACTION();
43
44   private static final String JavaDoc YY_ACTION_packed0 =
45     "\1\0\1\1\2\2\1\3\1\4\1\5";
46
47   private static int [] yy_unpack_YY_ACTION() {
48     int [] result = new int[7];
49     int offset = 0;
50     offset = yy_unpack_YY_ACTION(YY_ACTION_packed0, offset, result);
51     return result;
52   }
53
54   private static int yy_unpack_YY_ACTION(String JavaDoc packed, int offset, int [] result) {
55     int i = 0; /* index in packed string */
56     int j = offset; /* index in unpacked array */
57     int l = packed.length();
58     while (i < l) {
59       int count = packed.charAt(i++);
60       int value = packed.charAt(i++);
61       do result[j++] = value; while (--count > 0);
62     }
63     return j;
64   }
65
66
67   /**
68    * Translates a state to a row index in the transition table
69    */

70   private static final int [] yy_rowMap = yy_unpack_yy_rowMap();
71
72   private static final String JavaDoc yy_rowMap_packed0 =
73     "\0\0\0\10\0\20\0\10\0\30\0\10\0\10";
74
75   private static int [] yy_unpack_yy_rowMap() {
76     int [] result = new int[7];
77     int offset = 0;
78     offset = yy_unpack_yy_rowMap(yy_rowMap_packed0, offset, result);
79     return result;
80   }
81
82   private static int yy_unpack_yy_rowMap(String JavaDoc packed, int offset, int [] result) {
83     int i = 0; /* index in packed string */
84     int j = offset; /* index in unpacked array */
85     int l = packed.length();
86     while (i < l) {
87       int high = ((int) packed.charAt(i++)) << 16;
88       result[j++] = high | packed.charAt(i++);
89     }
90     return j;
91   }
92
93   /**
94    * The transition table of the DFA
95    */

96   private static final int [] yytrans = yy_unpack_yytrans();
97
98   private static final String JavaDoc yytrans_packed0 =
99     "\1\2\1\3\2\4\1\5\1\2\1\6\1\7\12\0"+
100     "\1\4\11\0\2\5\2\0";
101
102   private static int [] yy_unpack_yytrans() {
103     int [] result = new int[32];
104     int offset = 0;
105     offset = yy_unpack_yytrans(yytrans_packed0, offset, result);
106     return result;
107   }
108
109   private static int yy_unpack_yytrans(String JavaDoc packed, int offset, int [] result) {
110     int i = 0; /* index in packed string */
111     int j = offset; /* index in unpacked array */
112     int l = packed.length();
113     while (i < l) {
114       int count = packed.charAt(i++);
115       int value = packed.charAt(i++);
116       value--;
117       do result[j++] = value; while (--count > 0);
118     }
119     return j;
120   }
121
122
123   /* error codes */
124   private static final int YY_UNKNOWN_ERROR = 0;
125   private static final int YY_NO_MATCH = 1;
126   private static final int YY_PUSHBACK_2BIG = 2;
127
128   /* error messages for the codes above */
129   private static final String JavaDoc YY_ERROR_MSG[] = {
130     "Unkown internal scanner error",
131     "Error: could not match input",
132     "Error: pushback value was too large"
133   };
134
135   /**
136    * YY_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
137    */

138   private static final int [] YY_ATTRIBUTE = yy_unpack_YY_ATTRIBUTE();
139
140   private static final String JavaDoc YY_ATTRIBUTE_packed0 =
141     "\1\0\1\11\1\1\1\11\1\1\2\11";
142
143   private static int [] yy_unpack_YY_ATTRIBUTE() {
144     int [] result = new int[7];
145     int offset = 0;
146     offset = yy_unpack_YY_ATTRIBUTE(YY_ATTRIBUTE_packed0, offset, result);
147     return result;
148   }
149
150   private static int yy_unpack_YY_ATTRIBUTE(String JavaDoc packed, int offset, int [] result) {
151     int i = 0; /* index in packed string */
152     int j = offset; /* index in unpacked array */
153     int l = packed.length();
154     while (i < l) {
155       int count = packed.charAt(i++);
156       int value = packed.charAt(i++);
157       do result[j++] = value; while (--count > 0);
158     }
159     return j;
160   }
161
162   /** the input device */
163   private java.io.Reader JavaDoc yy_reader;
164
165   /** the current state of the DFA */
166   private int yy_state;
167
168   /** the current lexical state */
169   private int yy_lexical_state = YYINITIAL;
170
171   /** this buffer contains the current text to be matched and is
172       the source of the yytext() string */

173   private char yy_buffer[] = new char[YY_BUFFERSIZE];
174
175   /** the textposition at the last accepting state */
176   private int yy_markedPos;
177
178   /** the textposition at the last state to be included in yytext */
179   private int yy_pushbackPos;
180
181   /** the current text position in the buffer */
182   private int yy_currentPos;
183
184   /** startRead marks the beginning of the yytext() string in the buffer */
185   private int yy_startRead;
186
187   /** endRead marks the last character in the buffer, that has been read
188       from input */

189   private int yy_endRead;
190
191   /** number of newlines encountered up to the start of the matched text */
192   private int yyline;
193
194   /** the number of characters up to the start of the matched text */
195   private int yychar;
196
197   /**
198    * the number of characters from the last newline up to the start of the
199    * matched text
200    */

201   private int yycolumn;
202
203   /**
204    * yy_atBOL == true <=> the scanner is currently at the beginning of a line
205    */

206   private boolean yy_atBOL = true;
207
208   /** yy_atEOF == true <=> the scanner is at the EOF */
209   private boolean yy_atEOF;
210
211   /** denotes if the user-EOF-code has already been executed */
212   private boolean yy_eof_done;
213
214   /* user code: */
215     private Terminals t;
216     public void setTerminals(Terminals t) {
217         this.t = t;
218     }
219
220
221   /**
222    * Creates a new scanner
223    * There is also a java.io.InputStream version of this constructor.
224    *
225    * @param in the java.io.Reader to read input from.
226    */

227   public TestLexer03(java.io.Reader JavaDoc in) {
228     this.yy_reader = in;
229   }
230
231   /**
232    * Creates a new scanner.
233    * There is also java.io.Reader version of this constructor.
234    *
235    * @param in the java.io.Inputstream to read input from.
236    */

237   public TestLexer03(java.io.InputStream JavaDoc in) {
238     this(new java.io.InputStreamReader JavaDoc(in));
239   }
240
241
242   /**
243    * Refills the input buffer.
244    *
245    * @return <code>false</code>, iff there was new input.
246    *
247    * @exception IOException if any I/O-Error occurs
248    */

249   private boolean yy_refill() throws java.io.IOException JavaDoc {
250
251     /* first: make room (if you can) */
252     if (yy_startRead > 0) {
253       System.arraycopy(yy_buffer, yy_startRead,
254                        yy_buffer, 0,
255                        yy_endRead-yy_startRead);
256
257       /* translate stored positions */
258       yy_endRead-= yy_startRead;
259       yy_currentPos-= yy_startRead;
260       yy_markedPos-= yy_startRead;
261       yy_pushbackPos-= yy_startRead;
262       yy_startRead = 0;
263     }
264
265     /* is the buffer big enough? */
266     if (yy_currentPos >= yy_buffer.length) {
267       /* if not: blow it up */
268       char newBuffer[] = new char[yy_currentPos*2];
269       System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
270       yy_buffer = newBuffer;
271     }
272
273     /* finally: fill the buffer with new input */
274     int numRead = yy_reader.read(yy_buffer, yy_endRead,
275                                             yy_buffer.length-yy_endRead);
276
277     if (numRead < 0) {
278       return true;
279     }
280     else {
281       yy_endRead+= numRead;
282       return false;
283     }
284   }
285
286     
287   /**
288    * Closes the input stream.
289    */

290   public final void yyclose() throws java.io.IOException JavaDoc {
291     yy_atEOF = true; /* indicate end of file */
292     yy_endRead = yy_startRead; /* invalidate buffer */
293
294     if (yy_reader != null)
295       yy_reader.close();
296   }
297
298
299   /**
300    * Resets the scanner to read from a new input stream.
301    * Does not close the old reader.
302    *
303    * All internal variables are reset, the old input stream
304    * <b>cannot</b> be reused (internal buffer is discarded and lost).
305    * Lexical state is set to <tt>YY_INITIAL</tt>.
306    *
307    * @param reader the new input stream
308    */

309   public final void yyreset(java.io.Reader JavaDoc reader) throws java.io.IOException JavaDoc {
310     yy_reader = reader;
311     yy_atBOL = true;
312     yy_atEOF = false;
313     yy_endRead = yy_startRead = 0;
314     yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
315     yyline = yychar = yycolumn = 0;
316     yy_lexical_state = YYINITIAL;
317   }
318
319
320   /**
321    * Returns the current lexical state.
322    */

323   public final int yystate() {
324     return yy_lexical_state;
325   }
326
327
328   /**
329    * Enters a new lexical state
330    *
331    * @param newState the new lexical state
332    */

333   public final void yybegin(int newState) {
334     yy_lexical_state = newState;
335   }
336
337
338   /**
339    * Returns the text matched by the current regular expression.
340    */

341   public final String JavaDoc yytext() {
342     return new String JavaDoc( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
343   }
344
345
346   /**
347    * Returns the character at position <tt>pos</tt> from the
348    * matched text.
349    *
350    * It is equivalent to yytext().charAt(pos), but faster
351    *
352    * @param pos the position of the character to fetch.
353    * A value from 0 to yylength()-1.
354    *
355    * @return the character at position pos
356    */

357   public final char yycharat(int pos) {
358     return yy_buffer[yy_startRead+pos];
359   }
360
361
362   /**
363    * Returns the length of the matched text region.
364    */

365   public final int yylength() {
366     return yy_markedPos-yy_startRead;
367   }
368
369
370   /**
371    * Reports an error that occured while scanning.
372    *
373    * In a wellformed scanner (no or only correct usage of
374    * yypushback(int) and a match-all fallback rule) this method
375    * will only be called with things that "Can't Possibly Happen".
376    * If this method is called, something is seriously wrong
377    * (e.g. a JFlex bug producing a faulty scanner etc.).
378    *
379    * Usual syntax/scanner level error handling should be done
380    * in error fallback rules.
381    *
382    * @param errorCode the code of the errormessage to display
383    */

384   private void yy_ScanError(int errorCode) {
385     String JavaDoc message;
386     try {
387       message = YY_ERROR_MSG[errorCode];
388     }
389     catch (ArrayIndexOutOfBoundsException JavaDoc e) {
390       message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
391     }
392
393     throw new Error JavaDoc(message);
394   }
395
396
397   /**
398    * Pushes the specified amount of characters back into the input stream.
399    *
400    * They will be read again by then next call of the scanning method
401    *
402    * @param number the number of characters to be read again.
403    * This number must not be greater than yylength()!
404    */

405   public void yypushback(int number) {
406     if ( number > yylength() )
407       yy_ScanError(YY_PUSHBACK_2BIG);
408
409     yy_markedPos -= number;
410   }
411
412
413   /**
414    * Contains user EOF-code, which will be executed exactly once,
415    * when the end of file is reached
416    */

417   private void yy_do_eof() throws java.io.IOException JavaDoc {
418     if (!yy_eof_done) {
419       yy_eof_done = true;
420       yyclose();
421     }
422   }
423
424
425   /**
426    * Resumes scanning until the next regular expression is matched,
427    * the end of input is encountered or an I/O-Error occurs.
428    *
429    * @return the next token
430    * @exception IOException if any I/O-Error occurs
431    */

432   public Terminal nextToken() throws java.io.IOException JavaDoc {
433     int yy_input;
434     int yy_action;
435
436     // cached fields:
437
int yy_currentPos_l;
438     int yy_markedPos_l;
439     int yy_endRead_l = yy_endRead;
440     char [] yy_buffer_l = yy_buffer;
441     char [] yycmap_l = yycmap;
442
443     int [] yytrans_l = yytrans;
444     int [] yy_rowMap_l = yy_rowMap;
445     int [] yy_attr_l = YY_ATTRIBUTE;
446
447     while (true) {
448       yy_markedPos_l = yy_markedPos;
449
450       boolean yy_r = false;
451       for (yy_currentPos_l = yy_startRead; yy_currentPos_l < yy_markedPos_l;
452                                                              yy_currentPos_l++) {
453         switch (yy_buffer_l[yy_currentPos_l]) {
454         case '\u000B':
455         case '\u000C':
456         case '\u0085':
457         case '\u2028':
458         case '\u2029':
459           yyline++;
460           yycolumn = 0;
461           yy_r = false;
462           break;
463         case '\r':
464           yyline++;
465           yycolumn = 0;
466           yy_r = true;
467           break;
468         case '\n':
469           if (yy_r)
470             yy_r = false;
471           else {
472             yyline++;
473             yycolumn = 0;
474           }
475           break;
476         default:
477           yy_r = false;
478           yycolumn++;
479         }
480       }
481
482       if (yy_r) {
483         // peek one character ahead if it is \n (if we have counted one line too much)
484
boolean yy_peek;
485         if (yy_markedPos_l < yy_endRead_l)
486           yy_peek = yy_buffer_l[yy_markedPos_l] == '\n';
487         else if (yy_atEOF)
488           yy_peek = false;
489         else {
490           boolean eof = yy_refill();
491           yy_markedPos_l = yy_markedPos;
492           yy_buffer_l = yy_buffer;
493           if (eof)
494             yy_peek = false;
495           else
496             yy_peek = yy_buffer_l[yy_markedPos_l] == '\n';
497         }
498         if (yy_peek) yyline--;
499       }
500       yy_action = -1;
501
502       yy_currentPos_l = yy_currentPos = yy_startRead = yy_markedPos_l;
503   
504       yy_state = yy_lexical_state;
505
506
507       yy_forAction: {
508         while (true) {
509     
510           if (yy_currentPos_l < yy_endRead_l)
511             yy_input = yy_buffer_l[yy_currentPos_l++];
512           else if (yy_atEOF) {
513             yy_input = YYEOF;
514             break yy_forAction;
515           }
516           else {
517             // store back cached positions
518
yy_currentPos = yy_currentPos_l;
519             yy_markedPos = yy_markedPos_l;
520             boolean eof = yy_refill();
521             // get translated positions and possibly new buffer
522
yy_currentPos_l = yy_currentPos;
523             yy_markedPos_l = yy_markedPos;
524             yy_buffer_l = yy_buffer;
525             yy_endRead_l = yy_endRead;
526             if (eof) {
527               yy_input = YYEOF;
528               break yy_forAction;
529             }
530             else {
531               yy_input = yy_buffer_l[yy_currentPos_l++];
532             }
533           }
534           int yy_next = yytrans_l[ yy_rowMap_l[yy_state] + yycmap_l[yy_input] ];
535           if (yy_next == -1) break yy_forAction;
536           yy_state = yy_next;
537
538           int yy_attributes = yy_attr_l[yy_state];
539           if ( (yy_attributes & 1) == 1 ) {
540             yy_action = yy_state;
541             yy_markedPos_l = yy_currentPos_l;
542             if ( (yy_attributes & 8) == 8 ) break yy_forAction;
543           }
544
545         }
546       }
547
548       // store back cached position
549
yy_markedPos = yy_markedPos_l;
550
551       switch (yy_action < 0 ? yy_action : YY_ACTION[yy_action]) {
552         case 4:
553           { return t.find("EQUAL"); }
554         case 6: break;
555         case 1:
556           { throw new RuntimeException JavaDoc("illegal character \""+yytext()+"\""); }
557         case 7: break;
558         case 5:
559           { return t.find("STAR"); }
560         case 8: break;
561         case 3:
562           { return t.find("a"); }
563         case 9: break;
564         case 2:
565           { /*ignore*/ }
566         case 10: break;
567         default:
568           if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
569             yy_atEOF = true;
570             yy_do_eof();
571               { return t.EOF;
572  }
573           }
574           else {
575             yy_ScanError(YY_NO_MATCH);
576           }
577       }
578     }
579   }
580
581
582 }
583
Popular Tags