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