KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > pth > Lexer_c


1 /* The following code was generated by JFlex 1.3.5 on 7/4/05 2:46 PM */
2
3 package polyglot.pth;
4
5 import java_cup.runtime.Symbol;
6
7
8 /**
9  * This class is a scanner generated by
10  * <a HREF="http://www.jflex.de/">JFlex</a> 1.3.5
11  * on 7/4/05 2:46 PM from the specification file
12  * <tt>file:/Users/nystrom/Research/eclipse/polyglot/tools/pth/src/polyglot/pth/script.flex</tt>
13  */

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

29   final private static char [] yycmap = {
30      0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 2, 1, 0, 0,
31      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32      2, 0, 7, 5, 6, 0, 0, 0, 10, 11, 4, 0, 9, 0, 6, 3,
33      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 0, 0, 0, 0,
34      0, 6, 6, 21, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
35      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 12, 16, 13, 20, 0,
36      0, 6, 6, 6, 22, 6, 6, 6, 6, 6, 6, 6, 6, 6, 18, 6,
37      6, 6, 19, 6, 17, 6, 6, 6, 6, 6, 6, 14, 0, 15, 0, 0
38   };
39
40   /**
41    * Translates a state to a row index in the transition table
42    */

43   final private static int yy_rowMap [] = {
44         0, 23, 46, 46, 69, 92, 115, 46, 46, 46,
45        46, 46, 46, 46, 46, 46, 138, 161, 46, 184,
46       207, 230, 92, 46, 253, 46, 46, 46, 46, 276,
47        46
48   };
49
50   /**
51    * The packed transition table of the DFA (part 0)
52    */

53   final private static String JavaDoc yy_packed0 =
54     "\1\3\2\4\1\5\1\3\1\6\1\7\1\10\1\11"+
55     "\1\12\1\13\1\14\1\15\1\16\1\17\1\20\4\7"+
56     "\1\21\2\7\1\22\1\3\5\22\1\23\10\22\1\24"+
57     "\6\22\32\0\1\25\1\26\1\0\1\7\11\0\4\7"+
58     "\1\0\2\7\1\27\1\30\25\27\3\0\1\7\2\0"+
59     "\1\7\11\0\4\7\1\0\2\7\25\0\1\31\1\0"+
60     "\1\22\1\0\5\22\1\0\10\22\1\0\6\22\7\0"+
61     "\1\32\11\0\1\33\1\34\1\35\3\0\1\27\1\30"+
62     "\1\27\1\25\2\27\1\25\11\27\4\25\1\27\2\25"+
63     "\4\26\1\36\22\26\26\0\1\37\3\26\1\30\1\36"+
64     "\22\26";
65
66   /**
67    * The transition table of the DFA
68    */

69   final private static int yytrans [] = yy_unpack();
70
71
72   /* error codes */
73   final private static int YY_UNKNOWN_ERROR = 0;
74   final private static int YY_ILLEGAL_STATE = 1;
75   final private static int YY_NO_MATCH = 2;
76   final private static int YY_PUSHBACK_2BIG = 3;
77
78   /* error messages for the codes above */
79   final private static String JavaDoc YY_ERROR_MSG[] = {
80     "Unkown internal scanner error",
81     "Internal error: unknown state",
82     "Error: could not match input",
83     "Error: pushback value was too large"
84   };
85
86   /**
87    * YY_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
88    */

89   private final static byte YY_ATTRIBUTE[] = {
90      1, 0, 9, 9, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9,
91      1, 1, 9, 1, 1, 0, 0, 9, 0, 9, 9, 9, 9, 0, 9
92   };
93
94   /** the input device */
95   private java.io.Reader JavaDoc yy_reader;
96
97   /** the current state of the DFA */
98   private int yy_state;
99
100   /** the current lexical state */
101   private int yy_lexical_state = YYINITIAL;
102
103   /** this buffer contains the current text to be matched and is
104       the source of the yytext() string */

105   private char yy_buffer[] = new char[YY_BUFFERSIZE];
106
107   /** the textposition at the last accepting state */
108   private int yy_markedPos;
109
110   /** the textposition at the last state to be included in yytext */
111   private int yy_pushbackPos;
112
113   /** the current text position in the buffer */
114   private int yy_currentPos;
115
116   /** startRead marks the beginning of the yytext() string in the buffer */
117   private int yy_startRead;
118
119   /** endRead marks the last character in the buffer, that has been read
120       from input */

121   private int yy_endRead;
122
123   /** number of newlines encountered up to the start of the matched text */
124   private int yyline;
125
126   /** the number of characters up to the start of the matched text */
127   private int yychar;
128
129   /**
130    * the number of characters from the last newline up to the start of the
131    * matched text
132    */

133   private int yycolumn;
134
135   /**
136    * yy_atBOL == true <=> the scanner is currently at the beginning of a line
137    */

138   private boolean yy_atBOL = true;
139
140   /** yy_atEOF == true <=> the scanner is at the EOF */
141   private boolean yy_atEOF;
142
143   /** denotes if the user-EOF-code has already been executed */
144   private boolean yy_eof_done;
145
146   /* user code: */
147    StringBuffer JavaDoc string = new StringBuffer JavaDoc();
148
149
150   /**
151    * Creates a new scanner
152    * There is also a java.io.InputStream version of this constructor.
153    *
154    * @param in the java.io.Reader to read input from.
155    */

156   public Lexer_c(java.io.Reader JavaDoc in) {
157     this.yy_reader = in;
158   }
159
160   /**
161    * Creates a new scanner.
162    * There is also java.io.Reader version of this constructor.
163    *
164    * @param in the java.io.Inputstream to read input from.
165    */

166   public Lexer_c(java.io.InputStream JavaDoc in) {
167     this(new java.io.InputStreamReader JavaDoc(in));
168   }
169
170   /**
171    * Unpacks the split, compressed DFA transition table.
172    *
173    * @return the unpacked transition table
174    */

175   private static int [] yy_unpack() {
176     int [] trans = new int[299];
177     int offset = 0;
178     offset = yy_unpack(yy_packed0, offset, trans);
179     return trans;
180   }
181
182   /**
183    * Unpacks the compressed DFA transition table.
184    *
185    * @param packed the packed transition table
186    * @return the index of the last entry
187    */

188   private static int yy_unpack(String JavaDoc packed, int offset, int [] trans) {
189     int i = 0; /* index in packed string */
190     int j = offset; /* index in unpacked array */
191     int l = packed.length();
192     while (i < l) {
193       int count = packed.charAt(i++);
194       int value = packed.charAt(i++);
195       value--;
196       do trans[j++] = value; while (--count > 0);
197     }
198     return j;
199   }
200
201
202   /**
203    * Refills the input buffer.
204    *
205    * @return <code>false</code>, iff there was new input.
206    *
207    * @exception IOException if any I/O-Error occurs
208    */

209   private boolean yy_refill() throws java.io.IOException JavaDoc {
210
211     /* first: make room (if you can) */
212     if (yy_startRead > 0) {
213       System.arraycopy(yy_buffer, yy_startRead,
214                        yy_buffer, 0,
215                        yy_endRead-yy_startRead);
216
217       /* translate stored positions */
218       yy_endRead-= yy_startRead;
219       yy_currentPos-= yy_startRead;
220       yy_markedPos-= yy_startRead;
221       yy_pushbackPos-= yy_startRead;
222       yy_startRead = 0;
223     }
224
225     /* is the buffer big enough? */
226     if (yy_currentPos >= yy_buffer.length) {
227       /* if not: blow it up */
228       char newBuffer[] = new char[yy_currentPos*2];
229       System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
230       yy_buffer = newBuffer;
231     }
232
233     /* finally: fill the buffer with new input */
234     int numRead = yy_reader.read(yy_buffer, yy_endRead,
235                                             yy_buffer.length-yy_endRead);
236
237     if (numRead < 0) {
238       return true;
239     }
240     else {
241       yy_endRead+= numRead;
242       return false;
243     }
244   }
245
246
247   /**
248    * Closes the input stream.
249    */

250   final public void yyclose() throws java.io.IOException JavaDoc {
251     yy_atEOF = true; /* indicate end of file */
252     yy_endRead = yy_startRead; /* invalidate buffer */
253
254     if (yy_reader != null)
255       yy_reader.close();
256   }
257
258
259   /**
260    * Closes the current stream, and resets the
261    * scanner to read from a new input stream.
262    *
263    * All internal variables are reset, the old input stream
264    * <b>cannot</b> be reused (internal buffer is discarded and lost).
265    * Lexical state is set to <tt>YY_INITIAL</tt>.
266    *
267    * @param reader the new input stream
268    */

269   final public void yyreset(java.io.Reader JavaDoc reader) throws java.io.IOException JavaDoc {
270     yyclose();
271     yy_reader = reader;
272     yy_atBOL = true;
273     yy_atEOF = false;
274     yy_endRead = yy_startRead = 0;
275     yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
276     yyline = yychar = yycolumn = 0;
277     yy_lexical_state = YYINITIAL;
278   }
279
280
281   /**
282    * Returns the current lexical state.
283    */

284   final public int yystate() {
285     return yy_lexical_state;
286   }
287
288
289   /**
290    * Enters a new lexical state
291    *
292    * @param newState the new lexical state
293    */

294   final public void yybegin(int newState) {
295     yy_lexical_state = newState;
296   }
297
298
299   /**
300    * Returns the text matched by the current regular expression.
301    */

302   final public String JavaDoc yytext() {
303     return new String JavaDoc( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
304   }
305
306
307   /**
308    * Returns the character at position <tt>pos</tt> from the
309    * matched text.
310    *
311    * It is equivalent to yytext().charAt(pos), but faster
312    *
313    * @param pos the position of the character to fetch.
314    * A value from 0 to yylength()-1.
315    *
316    * @return the character at position pos
317    */

318   final public char yycharat(int pos) {
319     return yy_buffer[yy_startRead+pos];
320   }
321
322
323   /**
324    * Returns the length of the matched text region.
325    */

326   final public int yylength() {
327     return yy_markedPos-yy_startRead;
328   }
329
330
331   /**
332    * Reports an error that occured while scanning.
333    *
334    * In a wellformed scanner (no or only correct usage of
335    * yypushback(int) and a match-all fallback rule) this method
336    * will only be called with things that "Can't Possibly Happen".
337    * If this method is called, something is seriously wrong
338    * (e.g. a JFlex bug producing a faulty scanner etc.).
339    *
340    * Usual syntax/scanner level error handling should be done
341    * in error fallback rules.
342    *
343    * @param errorCode the code of the errormessage to display
344    */

345   private void yy_ScanError(int errorCode) {
346     String JavaDoc message;
347     try {
348       message = YY_ERROR_MSG[errorCode];
349     }
350     catch (ArrayIndexOutOfBoundsException JavaDoc e) {
351       message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
352     }
353
354     throw new Error JavaDoc(message);
355   }
356
357
358   /**
359    * Pushes the specified amount of characters back into the input stream.
360    *
361    * They will be read again by then next call of the scanning method
362    *
363    * @param number the number of characters to be read again.
364    * This number must not be greater than yylength()!
365    */

366   private void yypushback(int number) {
367     if ( number > yylength() )
368       yy_ScanError(YY_PUSHBACK_2BIG);
369
370     yy_markedPos -= number;
371   }
372
373
374   /**
375    * Contains user EOF-code, which will be executed exactly once,
376    * when the end of file is reached
377    */

378   private void yy_do_eof() throws java.io.IOException JavaDoc {
379     if (!yy_eof_done) {
380       yy_eof_done = true;
381       yyclose();
382     }
383   }
384
385
386   /**
387    * Resumes scanning until the next regular expression is matched,
388    * the end of input is encountered or an I/O-Error occurs.
389    *
390    * @return the next token
391    * @exception IOException if any I/O-Error occurs
392    */

393   public java_cup.runtime.Symbol next_token() throws java.io.IOException JavaDoc {
394     int yy_input;
395     int yy_action;
396
397     // cached fields:
398
int yy_currentPos_l;
399     int yy_startRead_l;
400     int yy_markedPos_l;
401     int yy_endRead_l = yy_endRead;
402     char [] yy_buffer_l = yy_buffer;
403     char [] yycmap_l = yycmap;
404
405     int [] yytrans_l = yytrans;
406     int [] yy_rowMap_l = yy_rowMap;
407     byte [] yy_attr_l = YY_ATTRIBUTE;
408
409     while (true) {
410       yy_markedPos_l = yy_markedPos;
411
412       yy_action = -1;
413
414       yy_startRead_l = yy_currentPos_l = yy_currentPos =
415                        yy_startRead = yy_markedPos_l;
416
417       yy_state = yy_lexical_state;
418
419
420       yy_forAction: {
421         while (true) {
422
423           if (yy_currentPos_l < yy_endRead_l)
424             yy_input = yy_buffer_l[yy_currentPos_l++];
425           else if (yy_atEOF) {
426             yy_input = YYEOF;
427             break yy_forAction;
428           }
429           else {
430             // store back cached positions
431
yy_currentPos = yy_currentPos_l;
432             yy_markedPos = yy_markedPos_l;
433             boolean eof = yy_refill();
434             // get translated positions and possibly new buffer
435
yy_currentPos_l = yy_currentPos;
436             yy_markedPos_l = yy_markedPos;
437             yy_buffer_l = yy_buffer;
438             yy_endRead_l = yy_endRead;
439             if (eof) {
440               yy_input = YYEOF;
441               break yy_forAction;
442             }
443             else {
444               yy_input = yy_buffer_l[yy_currentPos_l++];
445             }
446           }
447           int yy_next = yytrans_l[ yy_rowMap_l[yy_state] + yycmap_l[yy_input] ];
448           if (yy_next == -1) break yy_forAction;
449           yy_state = yy_next;
450
451           int yy_attributes = yy_attr_l[yy_state];
452           if ( (yy_attributes & 1) == 1 ) {
453             yy_action = yy_state;
454             yy_markedPos_l = yy_currentPos_l;
455             if ( (yy_attributes & 8) == 8 ) break yy_forAction;
456           }
457
458         }
459       }
460
461       // store back cached position
462
yy_markedPos = yy_markedPos_l;
463
464       switch (yy_action) {
465
466         case 8:
467           { return new Symbol(sym.SEMICOLON); }
468         case 32: break;
469         case 3:
470           { /* ignore white space. */ }
471         case 33: break;
472         case 28:
473           { string.append('\r'); }
474         case 34: break;
475         case 27:
476           { string.append('\n'); }
477         case 35: break;
478         case 26:
479           { string.append('\t'); }
480         case 36: break;
481         case 19:
482           { string.append('\\'); }
483         case 37: break;
484         case 25:
485           { string.append('\"'); }
486         case 38: break;
487         case 9:
488           { return new Symbol(sym.COMMA); }
489         case 39: break;
490         case 17:
491           { string.append( yytext() ); }
492         case 40: break;
493         case 7:
494           { string.setLength(0); yybegin(STRING_LIT); }
495         case 41: break;
496         case 2:
497         case 5:
498         case 16:
499           { throw new Error JavaDoc("Illegal character <"+
500                                                      yytext()+">"); }
501         case 42: break;
502         case 0:
503         case 4:
504         case 6:
505         case 20:
506           { return new Symbol(sym.IDENT, yytext()); }
507         case 43: break;
508         case 18:
509           { yybegin(YYINITIAL);
510                                     return new Symbol(sym.STRING_LITERAL,
511                                     string.toString()); }
512         case 44: break;
513         case 11:
514           { return new Symbol(sym.RPAREN); }
515         case 45: break;
516         case 10:
517           { return new Symbol(sym.LPAREN); }
518         case 46: break;
519         case 12:
520           { return new Symbol(sym.LBRACK); }
521         case 47: break;
522         case 13:
523           { return new Symbol(sym.RBRACK); }
524         case 48: break;
525         case 14:
526           { return new Symbol(sym.LBRACE); }
527         case 49: break;
528         case 15:
529           { return new Symbol(sym.RBRACE); }
530         case 50: break;
531         case 23:
532           { /* ignore */ }
533         case 51: break;
534         case 30:
535           { return new Symbol(sym.EOF); }
536         case 52: break;
537         default:
538           if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
539             yy_atEOF = true;
540             yy_do_eof();
541               { return (new Symbol(sym.EOF));
542  }
543           }
544           else {
545             yy_ScanError(YY_NO_MATCH);
546           }
547       }
548     }
549   }
550
551
552 }
553
Popular Tags