KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > lexer > demo > javacc > CalcTokenManager


1 /* Generated By:JavaCC: Do not edit this line. CalcTokenManager.java */
2                    // [MODIFY] Change the "Calc" to the target name of the language e.g. "MyLang".
3

4 package org.netbeans.modules.lexer.demo.javacc;
5                                                 // [MODIFY] Target package of the generated classes:
6

7 import org.netbeans.spi.lexer.javacc.CharStream;
8                                                  // do not remove or modify this line
9
import org.netbeans.spi.lexer.javacc.Token;
10                                             // do not remove or modify this line
11
import org.netbeans.spi.lexer.javacc.TokenMgrError;
12
13 public class CalcTokenManager implements CalcConstants
14 {
15   public java.io.PrintStream JavaDoc debugStream = System.out;
16   public void setDebugStream(java.io.PrintStream JavaDoc ds) { debugStream = ds; }
17 private final int jjStopStringLiteralDfa_0(int pos, long active0)
18 {
19    switch (pos)
20    {
21       default :
22          return -1;
23    }
24 }
25 private final int jjStartNfa_0(int pos, long active0)
26 {
27    return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
28 }
29 private final int jjStopAtPos(int pos, int kind)
30 {
31    jjmatchedKind = kind;
32    jjmatchedPos = pos;
33    return pos + 1;
34 }
35 private final int jjStartNfaWithStates_0(int pos, int kind, int state)
36 {
37    jjmatchedKind = kind;
38    jjmatchedPos = pos;
39    try { curChar = input_stream.readChar(); }
40    catch(java.io.IOException JavaDoc e) { return pos + 1; }
41    return jjMoveNfa_0(state, pos + 1);
42 }
43 private final int jjMoveStringLiteralDfa0_0()
44 {
45    switch(curChar)
46    {
47       case 40:
48          return jjStopAtPos(0, 10);
49       case 41:
50          return jjStopAtPos(0, 11);
51       case 42:
52          jjmatchedKind = 6;
53          return jjMoveStringLiteralDfa1_0(0x10100L);
54       case 43:
55          jjmatchedKind = 4;
56          return jjMoveStringLiteralDfa1_0(0x200L);
57       case 45:
58          return jjStopAtPos(0, 5);
59       case 47:
60          jjmatchedKind = 7;
61          return jjMoveStringLiteralDfa1_0(0x4L);
62       default :
63          return jjMoveNfa_0(1, 0);
64    }
65 }
66 private final int jjMoveStringLiteralDfa1_0(long active0)
67 {
68    try { curChar = input_stream.readChar(); }
69    catch(java.io.IOException JavaDoc e) {
70       jjStopStringLiteralDfa_0(0, active0);
71       return 1;
72    }
73    switch(curChar)
74    {
75       case 42:
76          if ((active0 & 0x4L) != 0L)
77             return jjStopAtPos(1, 2);
78          return jjMoveStringLiteralDfa2_0(active0, 0x100L);
79       case 43:
80          return jjMoveStringLiteralDfa2_0(active0, 0x200L);
81       case 47:
82          if ((active0 & 0x10000L) != 0L)
83             return jjStopAtPos(1, 16);
84          break;
85       default :
86          break;
87    }
88    return jjStartNfa_0(0, active0);
89 }
90 private final int jjMoveStringLiteralDfa2_0(long old0, long active0)
91 {
92    if (((active0 &= old0)) == 0L)
93       return jjStartNfa_0(0, old0);
94    try { curChar = input_stream.readChar(); }
95    catch(java.io.IOException JavaDoc e) {
96       jjStopStringLiteralDfa_0(1, active0);
97       return 2;
98    }
99    switch(curChar)
100    {
101       case 42:
102          if ((active0 & 0x100L) != 0L)
103             return jjStopAtPos(2, 8);
104          break;
105       case 43:
106          return jjMoveStringLiteralDfa3_0(active0, 0x200L);
107       default :
108          break;
109    }
110    return jjStartNfa_0(1, active0);
111 }
112 private final int jjMoveStringLiteralDfa3_0(long old0, long active0)
113 {
114    if (((active0 &= old0)) == 0L)
115       return jjStartNfa_0(1, old0);
116    try { curChar = input_stream.readChar(); }
117    catch(java.io.IOException JavaDoc e) {
118       jjStopStringLiteralDfa_0(2, active0);
119       return 3;
120    }
121    switch(curChar)
122    {
123       case 43:
124          return jjMoveStringLiteralDfa4_0(active0, 0x200L);
125       default :
126          break;
127    }
128    return jjStartNfa_0(2, active0);
129 }
130 private final int jjMoveStringLiteralDfa4_0(long old0, long active0)
131 {
132    if (((active0 &= old0)) == 0L)
133       return jjStartNfa_0(2, old0);
134    try { curChar = input_stream.readChar(); }
135    catch(java.io.IOException JavaDoc e) {
136       jjStopStringLiteralDfa_0(3, active0);
137       return 4;
138    }
139    switch(curChar)
140    {
141       case 43:
142          if ((active0 & 0x200L) != 0L)
143             return jjStopAtPos(4, 9);
144          break;
145       default :
146          break;
147    }
148    return jjStartNfa_0(3, active0);
149 }
150 private final void jjCheckNAdd(int state)
151 {
152    if (jjrounds[state] != jjround)
153    {
154       jjstateSet[jjnewStateCnt++] = state;
155       jjrounds[state] = jjround;
156    }
157 }
158 private final void jjAddStates(int start, int end)
159 {
160    do {
161       jjstateSet[jjnewStateCnt++] = jjnextStates[start];
162    } while (start++ != end);
163 }
164 private final void jjCheckNAddTwoStates(int state1, int state2)
165 {
166    jjCheckNAdd(state1);
167    jjCheckNAdd(state2);
168 }
169 private final void jjCheckNAddStates(int start, int end)
170 {
171    do {
172       jjCheckNAdd(jjnextStates[start]);
173    } while (start++ != end);
174 }
175 private final void jjCheckNAddStates(int start)
176 {
177    jjCheckNAdd(jjnextStates[start]);
178    jjCheckNAdd(jjnextStates[start + 1]);
179 }
180 private final int jjMoveNfa_0(int startState, int curPos)
181 {
182    int[] nextStates;
183    int startsAt = 0;
184    jjnewStateCnt = 14;
185    int i = 1;
186    jjstateSet[0] = startState;
187    int j, kind = 0x7fffffff;
188    for (;;)
189    {
190       if (++jjround == 0x7fffffff)
191          ReInitRounds();
192       if (curChar < 64)
193       {
194          long l = 1L << curChar;
195          MatchLoop: do
196          {
197             switch(jjstateSet[--i])
198             {
199                case 1:
200                   if ((0x3ff000000000000L & l) != 0L)
201                   {
202                      if (kind > 12)
203                         kind = 12;
204                      jjCheckNAddStates(0, 4);
205                   }
206                   else if ((0x100002600L & l) != 0L)
207                   {
208                      if (kind > 1)
209                         kind = 1;
210                      jjCheckNAdd(0);
211                   }
212                   else if (curChar == 46)
213                      jjCheckNAddTwoStates(12, 13);
214                   break;
215                case 0:
216                   if ((0x100002600L & l) == 0L)
217                      break;
218                   kind = 1;
219                   jjCheckNAdd(0);
220                   break;
221                case 2:
222                   if ((0x3ff000000000000L & l) == 0L)
223                      break;
224                   if (kind > 12)
225                      kind = 12;
226                   jjCheckNAddStates(5, 7);
227                   break;
228                case 3:
229                   if (curChar == 46)
230                      jjCheckNAdd(4);
231                   break;
232                case 4:
233                   if ((0x3ff000000000000L & l) == 0L)
234                      break;
235                   if (kind > 12)
236                      kind = 12;
237                   jjCheckNAddTwoStates(4, 5);
238                   break;
239                case 6:
240                   if ((0x280000000000L & l) != 0L)
241                      jjCheckNAdd(7);
242                   break;
243                case 7:
244                   if ((0x3ff000000000000L & l) == 0L)
245                      break;
246                   if (kind > 12)
247                      kind = 12;
248                   jjCheckNAdd(7);
249                   break;
250                case 8:
251                   if ((0x3ff000000000000L & l) == 0L)
252                      break;
253                   if (kind > 12)
254                      kind = 12;
255                   jjCheckNAddTwoStates(8, 9);
256                   break;
257                case 9:
258                   if (curChar == 46)
259                      jjCheckNAdd(10);
260                   break;
261                case 10:
262                   if ((0x3ff000000000000L & l) == 0L)
263                      break;
264                   if (kind > 12)
265                      kind = 12;
266                   jjCheckNAdd(10);
267                   break;
268                case 11:
269                   if (curChar == 46)
270                      jjCheckNAddTwoStates(12, 13);
271                   break;
272                case 12:
273                   if ((0x3ff000000000000L & l) == 0L)
274                      break;
275                   if (kind > 12)
276                      kind = 12;
277                   jjCheckNAddTwoStates(12, 5);
278                   break;
279                case 13:
280                   if ((0x3ff000000000000L & l) == 0L)
281                      break;
282                   if (kind > 12)
283                      kind = 12;
284                   jjCheckNAdd(13);
285                   break;
286                default : break;
287             }
288          } while(i != startsAt);
289       }
290       else if (curChar < 128)
291       {
292          long l = 1L << (curChar & 077);
293          MatchLoop: do
294          {
295             switch(jjstateSet[--i])
296             {
297                case 5:
298                   if ((0x2000000020L & l) != 0L)
299                      jjAddStates(8, 9);
300                   break;
301                default : break;
302             }
303          } while(i != startsAt);
304       }
305       else
306       {
307          int hiByte = (int)(curChar >> 8);
308          int i1 = hiByte >> 6;
309          long l1 = 1L << (hiByte & 077);
310          int i2 = (curChar & 0xff) >> 6;
311          long l2 = 1L << (curChar & 077);
312          MatchLoop: do
313          {
314             switch(jjstateSet[--i])
315             {
316                default : break;
317             }
318          } while(i != startsAt);
319       }
320       if (kind != 0x7fffffff)
321       {
322          jjmatchedKind = kind;
323          jjmatchedPos = curPos;
324          kind = 0x7fffffff;
325       }
326       ++curPos;
327       if ((i = jjnewStateCnt) == (startsAt = 14 - (jjnewStateCnt = startsAt)))
328          return curPos;
329       try { curChar = input_stream.readChar(); }
330       catch(java.io.IOException JavaDoc e) { return curPos; }
331    }
332 }
333 private final int jjMoveStringLiteralDfa0_1()
334 {
335    return jjMoveNfa_1(5, 0);
336 }
337 static final long[] jjbitVec0 = {
338    0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
339 };
340 static final long[] jjbitVec2 = {
341    0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
342 };
343 private final int jjMoveNfa_1(int startState, int curPos)
344 {
345    int[] nextStates;
346    int startsAt = 0;
347    jjnewStateCnt = 5;
348    int i = 1;
349    jjstateSet[0] = startState;
350    int j, kind = 0x7fffffff;
351    for (;;)
352    {
353       if (++jjround == 0x7fffffff)
354          ReInitRounds();
355       if (curChar < 64)
356       {
357          long l = 1L << curChar;
358          MatchLoop: do
359          {
360             switch(jjstateSet[--i])
361             {
362                case 5:
363                   if ((0xfffffbffffffffffL & l) != 0L)
364                      jjCheckNAddTwoStates(0, 1);
365                   else if (curChar == 42)
366                      jjCheckNAddStates(10, 12);
367                   break;
368                case 0:
369                   if ((0xfffffbffffffffffL & l) != 0L)
370                      jjCheckNAddTwoStates(0, 1);
371                   break;
372                case 1:
373                   if (curChar == 42)
374                      jjCheckNAddStates(10, 12);
375                   break;
376                case 2:
377                   if ((0xffff7bffffffffffL & l) != 0L)
378                      jjCheckNAddTwoStates(3, 1);
379                   break;
380                case 3:
381                   if ((0xfffffbffffffffffL & l) != 0L)
382                      jjCheckNAddTwoStates(3, 1);
383                   break;
384                case 4:
385                   if (curChar == 47 && kind > 3)
386                      kind = 3;
387                   break;
388                default : break;
389             }
390          } while(i != startsAt);
391       }
392       else if (curChar < 128)
393       {
394          long l = 1L << (curChar & 077);
395          MatchLoop: do
396          {
397             switch(jjstateSet[--i])
398             {
399                case 5:
400                case 0:
401                   jjCheckNAddTwoStates(0, 1);
402                   break;
403                case 2:
404                case 3:
405                   jjCheckNAddTwoStates(3, 1);
406                   break;
407                default : break;
408             }
409          } while(i != startsAt);
410       }
411       else
412       {
413          int hiByte = (int)(curChar >> 8);
414          int i1 = hiByte >> 6;
415          long l1 = 1L << (hiByte & 077);
416          int i2 = (curChar & 0xff) >> 6;
417          long l2 = 1L << (curChar & 077);
418          MatchLoop: do
419          {
420             switch(jjstateSet[--i])
421             {
422                case 5:
423                case 0:
424                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
425                      jjCheckNAddTwoStates(0, 1);
426                   break;
427                case 2:
428                case 3:
429                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
430                      jjCheckNAddTwoStates(3, 1);
431                   break;
432                default : break;
433             }
434          } while(i != startsAt);
435       }
436       if (kind != 0x7fffffff)
437       {
438          jjmatchedKind = kind;
439          jjmatchedPos = curPos;
440          kind = 0x7fffffff;
441       }
442       ++curPos;
443       if ((i = jjnewStateCnt) == (startsAt = 5 - (jjnewStateCnt = startsAt)))
444          return curPos;
445       try { curChar = input_stream.readChar(); }
446       catch(java.io.IOException JavaDoc e) { return curPos; }
447    }
448 }
449 static final int[] jjnextStates = {
450    2, 3, 5, 8, 9, 2, 3, 5, 6, 7, 1, 2, 4,
451 };
452 private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
453 {
454    switch(hiByte)
455    {
456       case 0:
457          return ((jjbitVec2[i2] & l2) != 0L);
458       default :
459          if ((jjbitVec0[i1] & l1) != 0L)
460             return true;
461          return false;
462    }
463 }
464 public static final String JavaDoc[] jjstrLiteralImages = {
465 "", null, "\57\52", null, "\53", "\55", "\52", "\57", "\52\52\52",
466 "\53\53\53\53\53", "\50", "\51", null, null, null, null, "\52\57", null, };
467 public static final String JavaDoc[] lexStateNames = {
468    "DEFAULT",
469    "IN_ML_COMMENT",
470 };
471 public static final int[] jjnewLexState = {
472    -1, -1, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
473 };
474 protected CharStream input_stream;
475 private final int[] jjrounds = new int[14];
476 private final int[] jjstateSet = new int[28];
477 protected char curChar;
478 public CalcTokenManager(CharStream stream)
479 {
480    input_stream = stream;
481 }
482 public CalcTokenManager(CharStream stream, int lexState)
483 {
484    this(stream);
485    SwitchTo(lexState);
486 }
487 public void ReInit(CharStream stream)
488 {
489    jjmatchedPos = jjnewStateCnt = 0;
490    curLexState = defaultLexState;
491    input_stream = stream;
492    ReInitRounds();
493 }
494 private final void ReInitRounds()
495 {
496    int i;
497    jjround = 0x80000001;
498    for (i = 14; i-- > 0;)
499       jjrounds[i] = 0x80000000;
500 }
501 public void ReInit(CharStream stream, int lexState)
502 {
503    ReInit(stream);
504    SwitchTo(lexState);
505 }
506 public void SwitchTo(int lexState)
507 {
508    if (lexState >= 2 || lexState < 0)
509       throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
510    else
511       curLexState = lexState;
512 }
513
514 protected Token jjFillToken()
515 {
516    Token t = Token.newToken(jjmatchedKind);
517    t.kind = jjmatchedKind;
518    String JavaDoc im = jjstrLiteralImages[jjmatchedKind];
519    t.image = (im == null) ? input_stream.GetImage() : im;
520    t.beginLine = input_stream.getBeginLine();
521    t.beginColumn = input_stream.getBeginColumn();
522    t.endLine = input_stream.getEndLine();
523    t.endColumn = input_stream.getEndColumn();
524    return t;
525 }
526
527 int curLexState = 0;
528 int defaultLexState = 0;
529 int jjnewStateCnt;
530 int jjround;
531 int jjmatchedPos;
532 int jjmatchedKind;
533
534 public Token getNextToken()
535 {
536   int kind;
537   Token specialToken = null;
538   Token matchedToken;
539   int curPos = 0;
540
541   EOFLoop :
542   for (;;)
543   {
544    try
545    {
546       curChar = input_stream.BeginToken();
547    }
548    catch(java.io.IOException JavaDoc e)
549    {
550       jjmatchedKind = 0;
551       matchedToken = jjFillToken();
552       return matchedToken;
553    }
554
555    switch(curLexState)
556    {
557      case 0:
558        jjmatchedKind = 0x7fffffff;
559        jjmatchedPos = 0;
560        curPos = jjMoveStringLiteralDfa0_0();
561        if (jjmatchedPos == 0 && jjmatchedKind > 17)
562        {
563           jjmatchedKind = 17;
564        }
565        break;
566      case 1:
567        jjmatchedKind = 0x7fffffff;
568        jjmatchedPos = 0;
569        curPos = jjMoveStringLiteralDfa0_1();
570        break;
571    }
572      if (jjmatchedKind != 0x7fffffff)
573      {
574         if (jjmatchedPos + 1 < curPos)
575            input_stream.backup(curPos - jjmatchedPos - 1);
576            matchedToken = jjFillToken();
577        if (jjnewLexState[jjmatchedKind] != -1)
578          curLexState = jjnewLexState[jjmatchedKind];
579            return matchedToken;
580      }
581      int error_line = input_stream.getEndLine();
582      int error_column = input_stream.getEndColumn();
583      String JavaDoc error_after = null;
584      boolean EOFSeen = false;
585      try { input_stream.readChar(); input_stream.backup(1); }
586      catch (java.io.IOException JavaDoc e1) {
587         EOFSeen = true;
588         error_after = curPos <= 1 ? "" : input_stream.GetImage();
589         if (curChar == '\n' || curChar == '\r') {
590            error_line++;
591            error_column = 0;
592         }
593         else
594            error_column++;
595      }
596      if (!EOFSeen) {
597         input_stream.backup(1);
598         error_after = curPos <= 1 ? "" : input_stream.GetImage();
599      }
600      throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
601   }
602 }
603
604 }
605
Popular Tags