KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestLexer


1 /* The following code was generated by JFlex 1.3.5 on 11/17/03 10:56 PM */
2
3 import ro.infoiasi.donald.compiler.cfg.*;
4 import ro.infoiasi.donald.compiler.parser.*;
5
6 /**
7  * This class is a scanner generated by
8  * <a HREF="http://www.jflex.de/">JFlex</a> 1.3.5
9  * on 11/17/03 10:56 PM from the specification file
10  * <tt>file:/D:/Dev/Java/Packages/parser/TestLexer.flex</tt>
11  */

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

26   final private static char [] yycmap = {
27      5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 2, 0, 3, 1, 5, 5,
28      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
29      3, 0, 0, 0, 4, 0, 0, 0, 8, 9, 7, 6, 0, 0, 0, 0,
30      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
31      0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
32      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 4,
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, 5
35   };
36
37   /**
38    * Translates a state to a row index in the transition table
39    */

40   final private static int yy_rowMap [] = {
41         0, 10, 20, 10, 30, 10, 10, 10, 10
42   };
43
44   /**
45    * The packed transition table of the DFA (part 0)
46    */

47   final private static String JavaDoc yy_packed0 =
48     "\1\2\1\3\2\4\1\5\1\2\1\6\1\7\1\10"+
49     "\1\11\14\0\1\4\13\0\2\5\4\0";
50
51   /**
52    * The transition table of the DFA
53    */

54   final private static int yytrans [] = yy_unpack();
55
56
57   /* error codes */
58   final private static int YY_UNKNOWN_ERROR = 0;
59   final private static int YY_ILLEGAL_STATE = 1;
60   final private static int YY_NO_MATCH = 2;
61   final private static int YY_PUSHBACK_2BIG = 3;
62
63   /* error messages for the codes above */
64   final private static String JavaDoc YY_ERROR_MSG[] = {
65     "Unkown internal scanner error",
66     "Internal error: unknown state",
67     "Error: could not match input",
68     "Error: pushback value was too large"
69   };
70
71   /**
72    * YY_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
73    */

74   private final static byte YY_ATTRIBUTE[] = {
75      0, 9, 1, 9, 1, 9, 9, 9, 9
76   };
77
78   /** the input device */
79   private java.io.Reader JavaDoc yy_reader;
80
81   /** the current state of the DFA */
82   private int yy_state;
83
84   /** the current lexical state */
85   private int yy_lexical_state = YYINITIAL;
86
87   /** this buffer contains the current text to be matched and is
88       the source of the yytext() string */

89   private char yy_buffer[] = new char[YY_BUFFERSIZE];
90
91   /** the textposition at the last accepting state */
92   private int yy_markedPos;
93
94   /** the textposition at the last state to be included in yytext */
95   private int yy_pushbackPos;
96
97   /** the current text position in the buffer */
98   private int yy_currentPos;
99
100   /** startRead marks the beginning of the yytext() string in the buffer */
101   private int yy_startRead;
102
103   /** endRead marks the last character in the buffer, that has been read
104       from input */

105   private int yy_endRead;
106
107   /** number of newlines encountered up to the start of the matched text */
108   private int yyline;
109
110   /** the number of characters up to the start of the matched text */
111   private int yychar;
112
113   /**
114    * the number of characters from the last newline up to the start of the
115    * matched text
116    */

117   private int yycolumn;
118
119   /**
120    * yy_atBOL == true <=> the scanner is currently at the beginning of a line
121    */

122   private boolean yy_atBOL = true;
123
124   /** yy_atEOF == true <=> the scanner is at the EOF */
125   private boolean yy_atEOF;
126
127   /** denotes if the user-EOF-code has already been executed */
128   private boolean yy_eof_done;
129
130   /* user code: */
131     private Terminals t;
132     public void setTerminals(Terminals t) {
133         this.t = t;
134     }
135
136
137   /**
138    * Creates a new scanner
139    * There is also a java.io.InputStream version of this constructor.
140    *
141    * @param in the java.io.Reader to read input from.
142    */

143   public TestLexer(java.io.Reader JavaDoc in) {
144     this.yy_reader = in;
145   }
146
147   /**
148    * Creates a new scanner.
149    * There is also java.io.Reader version of this constructor.
150    *
151    * @param in the java.io.Inputstream to read input from.
152    */

153   public TestLexer(java.io.InputStream JavaDoc in) {
154     this(new java.io.InputStreamReader JavaDoc(in));
155   }
156
157   /**
158    * Unpacks the split, compressed DFA transition table.
159    *
160    * @return the unpacked transition table
161    */

162   private static int [] yy_unpack() {
163     int [] trans = new int[40];
164     int offset = 0;
165     offset = yy_unpack(yy_packed0, offset, trans);
166     return trans;
167   }
168
169   /**
170    * Unpacks the compressed DFA transition table.
171    *
172    * @param packed the packed transition table
173    * @return the index of the last entry
174    */

175   private static int yy_unpack(String JavaDoc packed, int offset, int [] trans) {
176     int i = 0; /* index in packed string */
177     int j = offset; /* index in unpacked array */
178     int l = packed.length();
179     while (i < l) {
180       int count = packed.charAt(i++);
181       int value = packed.charAt(i++);
182       value--;
183       do trans[j++] = value; while (--count > 0);
184     }
185     return j;
186   }
187
188
189   /**
190    * Refills the input buffer.
191    *
192    * @return <code>false</code>, iff there was new input.
193    *
194    * @exception IOException if any I/O-Error occurs
195    */

196   private boolean yy_refill() throws java.io.IOException JavaDoc {
197
198     /* first: make room (if you can) */
199     if (yy_startRead > 0) {
200       System.arraycopy(yy_buffer, yy_startRead,
201                        yy_buffer, 0,
202                        yy_endRead-yy_startRead);
203
204       /* translate stored positions */
205       yy_endRead-= yy_startRead;
206       yy_currentPos-= yy_startRead;
207       yy_markedPos-= yy_startRead;
208       yy_pushbackPos-= yy_startRead;
209       yy_startRead = 0;
210     }
211
212     /* is the buffer big enough? */
213     if (yy_currentPos >= yy_buffer.length) {
214       /* if not: blow it up */
215       char newBuffer[] = new char[yy_currentPos*2];
216       System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
217       yy_buffer = newBuffer;
218     }
219
220     /* finally: fill the buffer with new input */
221     int numRead = yy_reader.read(yy_buffer, yy_endRead,
222                                             yy_buffer.length-yy_endRead);
223
224     if (numRead < 0) {
225       return true;
226     }
227     else {
228       yy_endRead+= numRead;
229       return false;
230     }
231   }
232
233
234   /**
235    * Closes the input stream.
236    */

237   final public void yyclose() throws java.io.IOException JavaDoc {
238     yy_atEOF = true; /* indicate end of file */
239     yy_endRead = yy_startRead; /* invalidate buffer */
240
241     if (yy_reader != null)
242       yy_reader.close();
243   }
244
245
246   /**
247    * Closes the current stream, and resets the
248    * scanner to read from a new input stream.
249    *
250    * All internal variables are reset, the old input stream
251    * <b>cannot</b> be reused (internal buffer is discarded and lost).
252    * Lexical state is set to <tt>YY_INITIAL</tt>.
253    *
254    * @param reader the new input stream
255    */

256   final public void yyreset(java.io.Reader JavaDoc reader) throws java.io.IOException JavaDoc {
257     yyclose();
258     yy_reader = reader;
259     yy_atBOL = true;
260     yy_atEOF = false;
261     yy_endRead = yy_startRead = 0;
262     yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
263     yyline = yychar = yycolumn = 0;
264     yy_lexical_state = YYINITIAL;
265   }
266
267
268   /**
269    * Returns the current lexical state.
270    */

271   final public int yystate() {
272     return yy_lexical_state;
273   }
274
275
276   /**
277    * Enters a new lexical state
278    *
279    * @param newState the new lexical state
280    */

281   final public void yybegin(int newState) {
282     yy_lexical_state = newState;
283   }
284
285
286   /**
287    * Returns the text matched by the current regular expression.
288    */

289   final public String JavaDoc yytext() {
290     return new String JavaDoc( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
291   }
292
293
294   /**
295    * Returns the character at position <tt>pos</tt> from the
296    * matched text.
297    *
298    * It is equivalent to yytext().charAt(pos), but faster
299    *
300    * @param pos the position of the character to fetch.
301    * A value from 0 to yylength()-1.
302    *
303    * @return the character at position pos
304    */

305   final public char yycharat(int pos) {
306     return yy_buffer[yy_startRead+pos];
307   }
308
309
310   /**
311    * Returns the length of the matched text region.
312    */

313   final public int yylength() {
314     return yy_markedPos-yy_startRead;
315   }
316
317
318   /**
319    * Reports an error that occured while scanning.
320    *
321    * In a wellformed scanner (no or only correct usage of
322    * yypushback(int) and a match-all fallback rule) this method
323    * will only be called with things that "Can't Possibly Happen".
324    * If this method is called, something is seriously wrong
325    * (e.g. a JFlex bug producing a faulty scanner etc.).
326    *
327    * Usual syntax/scanner level error handling should be done
328    * in error fallback rules.
329    *
330    * @param errorCode the code of the errormessage to display
331    */

332   private void yy_ScanError(int errorCode) {
333     String JavaDoc message;
334     try {
335       message = YY_ERROR_MSG[errorCode];
336     }
337     catch (ArrayIndexOutOfBoundsException JavaDoc e) {
338       message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
339     }
340
341     throw new Error JavaDoc(message);
342   }
343
344
345   /**
346    * Pushes the specified amount of characters back into the input stream.
347    *
348    * They will be read again by then next call of the scanning method
349    *
350    * @param number the number of characters to be read again.
351    * This number must not be greater than yylength()!
352    */

353   private void yypushback(int number) {
354     if ( number > yylength() )
355       yy_ScanError(YY_PUSHBACK_2BIG);
356
357     yy_markedPos -= number;
358   }
359
360
361   /**
362    * Contains user EOF-code, which will be executed exactly once,
363    * when the end of file is reached
364    */

365   private void yy_do_eof() throws java.io.IOException JavaDoc {
366     if (!yy_eof_done) {
367       yy_eof_done = true;
368       yyclose();
369     }
370   }
371
372
373   /**
374    * Resumes scanning until the next regular expression is matched,
375    * the end of input is encountered or an I/O-Error occurs.
376    *
377    * @return the next token
378    * @exception IOException if any I/O-Error occurs
379    */

380   public Terminal nextToken() throws java.io.IOException JavaDoc {
381     int yy_input;
382     int yy_action;
383
384     // cached fields:
385
int yy_currentPos_l;
386     int yy_startRead_l;
387     int yy_markedPos_l;
388     int yy_endRead_l = yy_endRead;
389     char [] yy_buffer_l = yy_buffer;
390     char [] yycmap_l = yycmap;
391
392     int [] yytrans_l = yytrans;
393     int [] yy_rowMap_l = yy_rowMap;
394     byte [] yy_attr_l = YY_ATTRIBUTE;
395
396     while (true) {
397       yy_markedPos_l = yy_markedPos;
398
399       boolean yy_r = false;
400       for (yy_currentPos_l = yy_startRead; yy_currentPos_l < yy_markedPos_l;
401                                                              yy_currentPos_l++) {
402         switch (yy_buffer_l[yy_currentPos_l]) {
403         case '\u000B':
404         case '\u000C':
405         case '\u0085':
406         case '\u2028':
407         case '\u2029':
408           yyline++;
409           yycolumn = 0;
410           yy_r = false;
411           break;
412         case '\r':
413           yyline++;
414           yycolumn = 0;
415           yy_r = true;
416           break;
417         case '\n':
418           if (yy_r)
419             yy_r = false;
420           else {
421             yyline++;
422             yycolumn = 0;
423           }
424           break;
425         default:
426           yy_r = false;
427           yycolumn++;
428         }
429       }
430
431       if (yy_r) {
432         // peek one character ahead if it is \n (if we have counted one line too much)
433
boolean yy_peek;
434         if (yy_markedPos_l < yy_endRead_l)
435           yy_peek = yy_buffer_l[yy_markedPos_l] == '\n';
436         else if (yy_atEOF)
437           yy_peek = false;
438         else {
439           boolean eof = yy_refill();
440           yy_markedPos_l = yy_markedPos;
441           yy_buffer_l = yy_buffer;
442           if (eof)
443             yy_peek = false;
444           else
445             yy_peek = yy_buffer_l[yy_markedPos_l] == '\n';
446         }
447         if (yy_peek) yyline--;
448       }
449       yy_action = -1;
450
451       yy_startRead_l = yy_currentPos_l = yy_currentPos =
452                        yy_startRead = yy_markedPos_l;
453
454       yy_state = yy_lexical_state;
455
456
457       yy_forAction: {
458         while (true) {
459
460           if (yy_currentPos_l < yy_endRead_l)
461             yy_input = yy_buffer_l[yy_currentPos_l++];
462           else if (yy_atEOF) {
463             yy_input = YYEOF;
464             break yy_forAction;
465           }
466           else {
467             // store back cached positions
468
yy_currentPos = yy_currentPos_l;
469             yy_markedPos = yy_markedPos_l;
470             boolean eof = yy_refill();
471             // get translated positions and possibly new buffer
472
yy_currentPos_l = yy_currentPos;
473             yy_markedPos_l = yy_markedPos;
474             yy_buffer_l = yy_buffer;
475             yy_endRead_l = yy_endRead;
476             if (eof) {
477               yy_input = YYEOF;
478               break yy_forAction;
479             }
480             else {
481               yy_input = yy_buffer_l[yy_currentPos_l++];
482             }
483           }
484           int yy_next = yytrans_l[ yy_rowMap_l[yy_state] + yycmap_l[yy_input] ];
485           if (yy_next == -1) break yy_forAction;
486           yy_state = yy_next;
487
488           int yy_attributes = yy_attr_l[yy_state];
489           if ( (yy_attributes & 1) == 1 ) {
490             yy_action = yy_state;
491             yy_markedPos_l = yy_currentPos_l;
492             if ( (yy_attributes & 8) == 8 ) break yy_forAction;
493           }
494
495         }
496       }
497
498       // store back cached position
499
yy_markedPos = yy_markedPos_l;
500
501       switch (yy_action) {
502
503         case 8:
504           { return t.find("RIGHT"); }
505         case 10: break;
506         case 7:
507           { return t.find("LEFT"); }
508         case 11: break;
509         case 5:
510           { return t.find("PLUS"); }
511         case 12: break;
512         case 6:
513           { return t.find("MUL"); }
514         case 13: break;
515         case 2:
516         case 3:
517           { /*ignore*/ }
518         case 14: break;
519         case 1:
520           { throw new RuntimeException JavaDoc("illegal character \""+yytext()+"\""); }
521         case 15: break;
522         case 4:
523           { return t.find("a"); }
524         case 16: break;
525         default:
526           if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
527             yy_atEOF = true;
528             yy_do_eof();
529               { return t.EOF;
530  }
531           }
532           else {
533             yy_ScanError(YY_NO_MATCH);
534           }
535       }
536     }
537   }
538
539
540 }
541
Popular Tags