KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > ANTLRTokdefLexer


1 // $ANTLR : "tokdef.g" -> "ANTLRTokdefLexer.java"$
2
package persistence.antlr;
3 import java.io.InputStream JavaDoc;
4 import persistence.antlr.TokenStreamException;
5 import persistence.antlr.TokenStreamIOException;
6 import persistence.antlr.TokenStreamRecognitionException;
7 import persistence.antlr.CharStreamException;
8 import persistence.antlr.CharStreamIOException;
9 import persistence.antlr.ANTLRException;
10 import java.io.Reader JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import persistence.antlr.CharScanner;
13 import persistence.antlr.InputBuffer;
14 import persistence.antlr.ByteBuffer;
15 import persistence.antlr.CharBuffer;
16 import persistence.antlr.Token;
17 import persistence.antlr.CommonToken;
18 import persistence.antlr.RecognitionException;
19 import persistence.antlr.NoViableAltForCharException;
20 import persistence.antlr.MismatchedCharException;
21 import persistence.antlr.TokenStream;
22 import persistence.antlr.ANTLRHashString;
23 import persistence.antlr.LexerSharedInputState;
24 import persistence.antlr.collections.impl.BitSet;
25 import persistence.antlr.SemanticException;
26
27 public class ANTLRTokdefLexer extends persistence.antlr.CharScanner implements ANTLRTokdefParserTokenTypes, TokenStream
28  {
29 public ANTLRTokdefLexer(InputStream JavaDoc in) {
30     this(new ByteBuffer(in));
31 }
32 public ANTLRTokdefLexer(Reader JavaDoc in) {
33     this(new CharBuffer(in));
34 }
35 public ANTLRTokdefLexer(InputBuffer ib) {
36     this(new LexerSharedInputState(ib));
37 }
38 public ANTLRTokdefLexer(LexerSharedInputState state) {
39     super(state);
40     caseSensitiveLiterals = true;
41     setCaseSensitive(true);
42     literals = new Hashtable JavaDoc();
43 }
44
45 public Token nextToken() throws TokenStreamException {
46     Token theRetToken=null;
47 tryAgain:
48     for (;;) {
49         Token _token = null;
50         int _ttype = Token.INVALID_TYPE;
51         resetText();
52         try { // for char stream error handling
53
try { // for lexical error handling
54
switch ( LA(1)) {
55                 case '\t': case '\n': case '\r': case ' ':
56                 {
57                     mWS(true);
58                     theRetToken=_returnToken;
59                     break;
60                 }
61                 case '(':
62                 {
63                     mLPAREN(true);
64                     theRetToken=_returnToken;
65                     break;
66                 }
67                 case ')':
68                 {
69                     mRPAREN(true);
70                     theRetToken=_returnToken;
71                     break;
72                 }
73                 case '=':
74                 {
75                     mASSIGN(true);
76                     theRetToken=_returnToken;
77                     break;
78                 }
79                 case '"':
80                 {
81                     mSTRING(true);
82                     theRetToken=_returnToken;
83                     break;
84                 }
85                 case 'A': case 'B': case 'C': case 'D':
86                 case 'E': case 'F': case 'G': case 'H':
87                 case 'I': case 'J': case 'K': case 'L':
88                 case 'M': case 'N': case 'O': case 'P':
89                 case 'Q': case 'R': case 'S': case 'T':
90                 case 'U': case 'V': case 'W': case 'X':
91                 case 'Y': case 'Z': case 'a': case 'b':
92                 case 'c': case 'd': case 'e': case 'f':
93                 case 'g': case 'h': case 'i': case 'j':
94                 case 'k': case 'l': case 'm': case 'n':
95                 case 'o': case 'p': case 'q': case 'r':
96                 case 's': case 't': case 'u': case 'v':
97                 case 'w': case 'x': case 'y': case 'z':
98                 {
99                     mID(true);
100                     theRetToken=_returnToken;
101                     break;
102                 }
103                 case '0': case '1': case '2': case '3':
104                 case '4': case '5': case '6': case '7':
105                 case '8': case '9':
106                 {
107                     mINT(true);
108                     theRetToken=_returnToken;
109                     break;
110                 }
111                 default:
112                     if ((LA(1)=='/') && (LA(2)=='/')) {
113                         mSL_COMMENT(true);
114                         theRetToken=_returnToken;
115                     }
116                     else if ((LA(1)=='/') && (LA(2)=='*')) {
117                         mML_COMMENT(true);
118                         theRetToken=_returnToken;
119                     }
120                 else {
121                     if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(Token.EOF_TYPE);}
122                 else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
123                 }
124                 }
125                 if ( _returnToken==null ) continue tryAgain; // found SKIP token
126
_ttype = _returnToken.getType();
127                 _returnToken.setType(_ttype);
128                 return _returnToken;
129             }
130             catch (RecognitionException e) {
131                 throw new TokenStreamRecognitionException(e);
132             }
133         }
134         catch (CharStreamException cse) {
135             if ( cse instanceof CharStreamIOException ) {
136                 throw new TokenStreamIOException(((CharStreamIOException)cse).io);
137             }
138             else {
139                 throw new TokenStreamException(cse.getMessage());
140             }
141         }
142     }
143 }
144
145     public final void mWS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
146         int _ttype; Token _token=null; int _begin=text.length();
147         _ttype = WS;
148         int _saveIndex;
149         
150         {
151         switch ( LA(1)) {
152         case ' ':
153         {
154             match(' ');
155             break;
156         }
157         case '\t':
158         {
159             match('\t');
160             break;
161         }
162         case '\r':
163         {
164             match('\r');
165             {
166             if ((LA(1)=='\n')) {
167                 match('\n');
168             }
169             else {
170             }
171             
172             }
173             newline();
174             break;
175         }
176         case '\n':
177         {
178             match('\n');
179             newline();
180             break;
181         }
182         default:
183         {
184             throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
185         }
186         }
187         }
188         _ttype = Token.SKIP;
189         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
190             _token = makeToken(_ttype);
191             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
192         }
193         _returnToken = _token;
194     }
195     
196     public final void mSL_COMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
197         int _ttype; Token _token=null; int _begin=text.length();
198         _ttype = SL_COMMENT;
199         int _saveIndex;
200         
201         match("//");
202         {
203         _loop234:
204         do {
205             if ((_tokenSet_0.member(LA(1)))) {
206                 {
207                 match(_tokenSet_0);
208                 }
209             }
210             else {
211                 break _loop234;
212             }
213             
214         } while (true);
215         }
216         {
217         switch ( LA(1)) {
218         case '\n':
219         {
220             match('\n');
221             break;
222         }
223         case '\r':
224         {
225             match('\r');
226             {
227             if ((LA(1)=='\n')) {
228                 match('\n');
229             }
230             else {
231             }
232             
233             }
234             break;
235         }
236         default:
237         {
238             throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
239         }
240         }
241         }
242         _ttype = Token.SKIP; newline();
243         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
244             _token = makeToken(_ttype);
245             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
246         }
247         _returnToken = _token;
248     }
249     
250     public final void mML_COMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
251         int _ttype; Token _token=null; int _begin=text.length();
252         _ttype = ML_COMMENT;
253         int _saveIndex;
254         
255         match("/*");
256         {
257         _loop239:
258         do {
259             if ((LA(1)=='*') && (_tokenSet_1.member(LA(2)))) {
260                 match('*');
261                 matchNot('/');
262             }
263             else if ((LA(1)=='\n')) {
264                 match('\n');
265                 newline();
266             }
267             else if ((_tokenSet_2.member(LA(1)))) {
268                 matchNot('*');
269             }
270             else {
271                 break _loop239;
272             }
273             
274         } while (true);
275         }
276         match("*/");
277         _ttype = Token.SKIP;
278         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
279             _token = makeToken(_ttype);
280             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
281         }
282         _returnToken = _token;
283     }
284     
285     public final void mLPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
286         int _ttype; Token _token=null; int _begin=text.length();
287         _ttype = LPAREN;
288         int _saveIndex;
289         
290         match('(');
291         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
292             _token = makeToken(_ttype);
293             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
294         }
295         _returnToken = _token;
296     }
297     
298     public final void mRPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
299         int _ttype; Token _token=null; int _begin=text.length();
300         _ttype = RPAREN;
301         int _saveIndex;
302         
303         match(')');
304         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
305             _token = makeToken(_ttype);
306             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
307         }
308         _returnToken = _token;
309     }
310     
311     public final void mASSIGN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
312         int _ttype; Token _token=null; int _begin=text.length();
313         _ttype = ASSIGN;
314         int _saveIndex;
315         
316         match('=');
317         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
318             _token = makeToken(_ttype);
319             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
320         }
321         _returnToken = _token;
322     }
323     
324     public final void mSTRING(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
325         int _ttype; Token _token=null; int _begin=text.length();
326         _ttype = STRING;
327         int _saveIndex;
328         
329         match('"');
330         {
331         _loop245:
332         do {
333             if ((LA(1)=='\\')) {
334                 mESC(false);
335             }
336             else if ((_tokenSet_3.member(LA(1)))) {
337                 matchNot('"');
338             }
339             else {
340                 break _loop245;
341             }
342             
343         } while (true);
344         }
345         match('"');
346         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
347             _token = makeToken(_ttype);
348             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
349         }
350         _returnToken = _token;
351     }
352     
353     protected final void mESC(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
354         int _ttype; Token _token=null; int _begin=text.length();
355         _ttype = ESC;
356         int _saveIndex;
357         
358         match('\\');
359         {
360         switch ( LA(1)) {
361         case 'n':
362         {
363             match('n');
364             break;
365         }
366         case 'r':
367         {
368             match('r');
369             break;
370         }
371         case 't':
372         {
373             match('t');
374             break;
375         }
376         case 'b':
377         {
378             match('b');
379             break;
380         }
381         case 'f':
382         {
383             match('f');
384             break;
385         }
386         case '"':
387         {
388             match('"');
389             break;
390         }
391         case '\'':
392         {
393             match('\'');
394             break;
395         }
396         case '\\':
397         {
398             match('\\');
399             break;
400         }
401         case '0': case '1': case '2': case '3':
402         {
403             {
404             matchRange('0','3');
405             }
406             {
407             if (((LA(1) >= '0' && LA(1) <= '9')) && ((LA(2) >= '\u0003' && LA(2) <= '\u00ff'))) {
408                 mDIGIT(false);
409                 {
410                 if (((LA(1) >= '0' && LA(1) <= '9')) && ((LA(2) >= '\u0003' && LA(2) <= '\u00ff'))) {
411                     mDIGIT(false);
412                 }
413                 else if (((LA(1) >= '\u0003' && LA(1) <= '\u00ff')) && (true)) {
414                 }
415                 else {
416                     throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
417                 }
418                 
419                 }
420             }
421             else if (((LA(1) >= '\u0003' && LA(1) <= '\u00ff')) && (true)) {
422             }
423             else {
424                 throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
425             }
426             
427             }
428             break;
429         }
430         case '4': case '5': case '6': case '7':
431         {
432             {
433             matchRange('4','7');
434             }
435             {
436             if (((LA(1) >= '0' && LA(1) <= '9')) && ((LA(2) >= '\u0003' && LA(2) <= '\u00ff'))) {
437                 mDIGIT(false);
438             }
439             else if (((LA(1) >= '\u0003' && LA(1) <= '\u00ff')) && (true)) {
440             }
441             else {
442                 throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
443             }
444             
445             }
446             break;
447         }
448         case 'u':
449         {
450             match('u');
451             mXDIGIT(false);
452             mXDIGIT(false);
453             mXDIGIT(false);
454             mXDIGIT(false);
455             break;
456         }
457         default:
458         {
459             throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
460         }
461         }
462         }
463         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
464             _token = makeToken(_ttype);
465             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
466         }
467         _returnToken = _token;
468     }
469     
470     protected final void mDIGIT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
471         int _ttype; Token _token=null; int _begin=text.length();
472         _ttype = DIGIT;
473         int _saveIndex;
474         
475         matchRange('0','9');
476         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
477             _token = makeToken(_ttype);
478             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
479         }
480         _returnToken = _token;
481     }
482     
483     protected final void mXDIGIT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
484         int _ttype; Token _token=null; int _begin=text.length();
485         _ttype = XDIGIT;
486         int _saveIndex;
487         
488         switch ( LA(1)) {
489         case '0': case '1': case '2': case '3':
490         case '4': case '5': case '6': case '7':
491         case '8': case '9':
492         {
493             matchRange('0','9');
494             break;
495         }
496         case 'a': case 'b': case 'c': case 'd':
497         case 'e': case 'f':
498         {
499             matchRange('a','f');
500             break;
501         }
502         case 'A': case 'B': case 'C': case 'D':
503         case 'E': case 'F':
504         {
505             matchRange('A','F');
506             break;
507         }
508         default:
509         {
510             throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
511         }
512         }
513         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
514             _token = makeToken(_ttype);
515             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
516         }
517         _returnToken = _token;
518     }
519     
520     public final void mID(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
521         int _ttype; Token _token=null; int _begin=text.length();
522         _ttype = ID;
523         int _saveIndex;
524         
525         {
526         switch ( LA(1)) {
527         case 'a': case 'b': case 'c': case 'd':
528         case 'e': case 'f': case 'g': case 'h':
529         case 'i': case 'j': case 'k': case 'l':
530         case 'm': case 'n': case 'o': case 'p':
531         case 'q': case 'r': case 's': case 't':
532         case 'u': case 'v': case 'w': case 'x':
533         case 'y': case 'z':
534         {
535             matchRange('a','z');
536             break;
537         }
538         case 'A': case 'B': case 'C': case 'D':
539         case 'E': case 'F': case 'G': case 'H':
540         case 'I': case 'J': case 'K': case 'L':
541         case 'M': case 'N': case 'O': case 'P':
542         case 'Q': case 'R': case 'S': case 'T':
543         case 'U': case 'V': case 'W': case 'X':
544         case 'Y': case 'Z':
545         {
546             matchRange('A','Z');
547             break;
548         }
549         default:
550         {
551             throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
552         }
553         }
554         }
555         {
556         _loop258:
557         do {
558             switch ( LA(1)) {
559             case 'a': case 'b': case 'c': case 'd':
560             case 'e': case 'f': case 'g': case 'h':
561             case 'i': case 'j': case 'k': case 'l':
562             case 'm': case 'n': case 'o': case 'p':
563             case 'q': case 'r': case 's': case 't':
564             case 'u': case 'v': case 'w': case 'x':
565             case 'y': case 'z':
566             {
567                 matchRange('a','z');
568                 break;
569             }
570             case 'A': case 'B': case 'C': case 'D':
571             case 'E': case 'F': case 'G': case 'H':
572             case 'I': case 'J': case 'K': case 'L':
573             case 'M': case 'N': case 'O': case 'P':
574             case 'Q': case 'R': case 'S': case 'T':
575             case 'U': case 'V': case 'W': case 'X':
576             case 'Y': case 'Z':
577             {
578                 matchRange('A','Z');
579                 break;
580             }
581             case '_':
582             {
583                 match('_');
584                 break;
585             }
586             case '0': case '1': case '2': case '3':
587             case '4': case '5': case '6': case '7':
588             case '8': case '9':
589             {
590                 matchRange('0','9');
591                 break;
592             }
593             default:
594             {
595                 break _loop258;
596             }
597             }
598         } while (true);
599         }
600         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
601             _token = makeToken(_ttype);
602             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
603         }
604         _returnToken = _token;
605     }
606     
607     public final void mINT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
608         int _ttype; Token _token=null; int _begin=text.length();
609         _ttype = INT;
610         int _saveIndex;
611         
612         {
613         int _cnt261=0;
614         _loop261:
615         do {
616             if (((LA(1) >= '0' && LA(1) <= '9'))) {
617                 mDIGIT(false);
618             }
619             else {
620                 if ( _cnt261>=1 ) { break _loop261; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
621             }
622             
623             _cnt261++;
624         } while (true);
625         }
626         if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
627             _token = makeToken(_ttype);
628             _token.setText(new String JavaDoc(text.getBuffer(), _begin, text.length()-_begin));
629         }
630         _returnToken = _token;
631     }
632     
633     
634     private static final long[] mk_tokenSet_0() {
635         long[] data = new long[8];
636         data[0]=-9224L;
637         for (int i = 1; i<=3; i++) { data[i]=-1L; }
638         return data;
639     }
640     public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
641     private static final long[] mk_tokenSet_1() {
642         long[] data = new long[8];
643         data[0]=-140737488355336L;
644         for (int i = 1; i<=3; i++) { data[i]=-1L; }
645         return data;
646     }
647     public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
648     private static final long[] mk_tokenSet_2() {
649         long[] data = new long[8];
650         data[0]=-4398046512136L;
651         for (int i = 1; i<=3; i++) { data[i]=-1L; }
652         return data;
653     }
654     public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
655     private static final long[] mk_tokenSet_3() {
656         long[] data = new long[8];
657         data[0]=-17179869192L;
658         data[1]=-268435457L;
659         for (int i = 2; i<=3; i++) { data[i]=-1L; }
660         return data;
661     }
662     public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
663     
664     }
665
Popular Tags