KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestLexer5


1 /* The following code was generated by JFlex 1.4_5 on 12/8/03 12:07 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/8/03 12:07 PM from the specification file
12  * <tt>TestLexer5.flex</tt>
13  */

14 public class TestLexer5 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      0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 3, 1, 0, 0,
30      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31      3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0,
33      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35      0, 11, 4, 0, 9, 5, 0, 6, 0, 7, 0, 0, 0, 0, 8, 0,
36      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
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\2\1\1\3\1\4\1\5\3\0"+
46     "\1\6\1\0\1\7";
47
48   private static int [] yy_unpack_YY_ACTION() {
49     int [] result = new int[15];
50     int offset = 0;
51     offset = yy_unpack_YY_ACTION(YY_ACTION_packed0, offset, result);
52     return result;
53   }
54
55   private static int yy_unpack_YY_ACTION(String JavaDoc packed, int offset, int [] result) {
56     int i = 0; /* index in packed string */
57     int j = offset; /* index in unpacked array */
58     int l = packed.length();
59     while (i < l) {
60       int count = packed.charAt(i++);
61       int value = packed.charAt(i++);
62       do result[j++] = value; while (--count > 0);
63     }
64     return j;
65   }
66
67
68   /**
69    * Translates a state to a row index in the transition table
70    */

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

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

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

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

193   private int yy_endRead;
194
195   /** number of newlines encountered up to the start of the matched text */
196   private int yyline;
197
198   /** the number of characters up to the start of the matched text */
199   private int yychar;
200
201   /**
202    * the number of characters from the last newline up to the start of the
203    * matched text
204    */

205   private int yycolumn;
206
207   /**
208    * yy_atBOL == true <=> the scanner is currently at the beginning of a line
209    */

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

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

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

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

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

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

327   public final int yystate() {
328     return yy_lexical_state;
329   }
330
331
332   /**
333    * Enters a new lexical state
334    *
335    * @param newState the new lexical state
336    */

337   public final void yybegin(int newState) {
338     yy_lexical_state = newState;
339   }
340
341
342   /**
343    * Returns the text matched by the current regular expression.
344    */

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

361   public final char yycharat(int pos) {
362     return yy_buffer[yy_startRead+pos];
363   }
364
365
366   /**
367    * Returns the length of the matched text region.
368    */

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

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

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

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

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