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