001/* Generated By:JavaCC: Do not edit this line. UParserTokenManager.java */ 002/* 003 004 Copyright (c) 1998-2008 The Regents of the University of California. 005 All rights reserved. 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the above 009 copyright notice and the following two paragraphs appear in all copies 010 of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 ENHANCEMENTS, OR MODIFICATIONS. 024 025 PT_COPYRIGHT_VERSION_3 026 COPYRIGHTENDKEY 027*/ 028 029package ptolemy.moml.unit; 030 031/** Token Manager. */ 032public class UParserTokenManager implements UParserConstants { 033 034 /** Debug output. */ 035 public java.io.PrintStream debugStream = System.out; 036 037 /** Set debug output. */ 038 public void setDebugStream(java.io.PrintStream ds) { 039 debugStream = ds; 040 } 041 042 private int jjStopAtPos(int pos, int kind) { 043 jjmatchedKind = kind; 044 jjmatchedPos = pos; 045 return pos + 1; 046 } 047 048 private int jjMoveStringLiteralDfa0_0() { 049 switch (curChar) { 050 case 36: 051 return jjStartNfaWithStates_0(0, 12, 11); 052 case 40: 053 return jjStopAtPos(0, 20); 054 case 41: 055 return jjStopAtPos(0, 21); 056 case 42: 057 return jjStopAtPos(0, 7); 058 case 43: 059 return jjStopAtPos(0, 5); 060 case 45: 061 return jjStopAtPos(0, 6); 062 case 47: 063 return jjStopAtPos(0, 8); 064 case 59: 065 return jjStopAtPos(0, 13); 066 case 60: 067 return jjStopAtPos(0, 11); 068 case 61: 069 return jjStopAtPos(0, 10); 070 case 94: 071 return jjStopAtPos(0, 9); 072 default: 073 return jjMoveNfa_0(0, 0); 074 } 075 } 076 077 private int jjStartNfaWithStates_0(int pos, int kind, int state) { 078 jjmatchedKind = kind; 079 jjmatchedPos = pos; 080 try { 081 curChar = input_stream.readChar(); 082 } catch (java.io.IOException e) { 083 return pos + 1; 084 } 085 return jjMoveNfa_0(state, pos + 1); 086 } 087 088 private int jjMoveNfa_0(int startState, int curPos) { 089 int startsAt = 0; 090 jjnewStateCnt = 28; 091 int i = 1; 092 jjstateSet[0] = startState; 093 int kind = 0x7fffffff; 094 for (;;) { 095 if (++jjround == 0x7fffffff) { 096 ReInitRounds(); 097 } 098 if (curChar < 64) { 099 long l = 1L << curChar; 100 do { 101 switch (jjstateSet[--i]) { 102 case 0: 103 if ((0x3ff000000000000L & l) != 0L) { 104 jjCheckNAddStates(0, 6); 105 } else if (curChar == 36) { 106 jjstateSet[jjnewStateCnt++] = 11; 107 } else if (curChar == 46) { 108 jjCheckNAdd(3); 109 } 110 if ((0x3fe000000000000L & l) != 0L) { 111 if (kind > 14) { 112 kind = 14; 113 } 114 jjCheckNAdd(1); 115 } 116 break; 117 case 1: 118 if ((0x3ff000000000000L & l) == 0L) { 119 break; 120 } 121 if (kind > 14) { 122 kind = 14; 123 } 124 jjCheckNAdd(1); 125 break; 126 case 2: 127 if (curChar == 46) { 128 jjCheckNAdd(3); 129 } 130 break; 131 case 3: 132 if ((0x3ff000000000000L & l) == 0L) { 133 break; 134 } 135 if (kind > 16) { 136 kind = 16; 137 } 138 jjCheckNAddStates(7, 9); 139 break; 140 case 5: 141 if ((0x280000000000L & l) != 0L) { 142 jjCheckNAdd(6); 143 } 144 break; 145 case 6: 146 if ((0x3ff000000000000L & l) == 0L) { 147 break; 148 } 149 if (kind > 16) { 150 kind = 16; 151 } 152 jjCheckNAddTwoStates(6, 7); 153 break; 154 case 9: 155 if ((0x3ff000000000000L & l) == 0L) { 156 break; 157 } 158 if (kind > 17) { 159 kind = 17; 160 } 161 jjstateSet[jjnewStateCnt++] = 9; 162 break; 163 case 10: 164 if (curChar == 36) { 165 jjstateSet[jjnewStateCnt++] = 11; 166 } 167 break; 168 case 12: 169 if ((0x3ff000000000000L & l) == 0L) { 170 break; 171 } 172 if (kind > 19) { 173 kind = 19; 174 } 175 jjstateSet[jjnewStateCnt++] = 12; 176 break; 177 case 13: 178 if ((0x3ff000000000000L & l) != 0L) { 179 jjCheckNAddStates(0, 6); 180 } 181 break; 182 case 14: 183 if ((0x3ff000000000000L & l) != 0L) { 184 jjCheckNAddTwoStates(14, 15); 185 } 186 break; 187 case 15: 188 if (curChar == 46) { 189 jjCheckNAdd(16); 190 } 191 break; 192 case 16: 193 if ((0x3ff000000000000L & l) == 0L) { 194 break; 195 } 196 if (kind > 16) { 197 kind = 16; 198 } 199 jjCheckNAddStates(10, 12); 200 break; 201 case 18: 202 if ((0x280000000000L & l) != 0L) { 203 jjCheckNAdd(19); 204 } 205 break; 206 case 19: 207 if ((0x3ff000000000000L & l) == 0L) { 208 break; 209 } 210 if (kind > 16) { 211 kind = 16; 212 } 213 jjCheckNAddTwoStates(19, 7); 214 break; 215 case 20: 216 if ((0x3ff000000000000L & l) != 0L) { 217 jjCheckNAddTwoStates(20, 21); 218 } 219 break; 220 case 22: 221 if ((0x280000000000L & l) != 0L) { 222 jjCheckNAdd(23); 223 } 224 break; 225 case 23: 226 if ((0x3ff000000000000L & l) == 0L) { 227 break; 228 } 229 if (kind > 16) { 230 kind = 16; 231 } 232 jjCheckNAddTwoStates(23, 7); 233 break; 234 case 24: 235 if ((0x3ff000000000000L & l) != 0L) { 236 jjCheckNAddStates(13, 15); 237 } 238 break; 239 case 26: 240 if ((0x280000000000L & l) != 0L) { 241 jjCheckNAdd(27); 242 } 243 break; 244 case 27: 245 if ((0x3ff000000000000L & l) != 0L) { 246 jjCheckNAddTwoStates(27, 7); 247 } 248 break; 249 default: 250 break; 251 } 252 } while (i != startsAt); 253 } else if (curChar < 128) { 254 long l = 1L << (curChar & 077); 255 do { 256 switch (jjstateSet[--i]) { 257 case 0: 258 case 8: 259 if ((0x7fffffe87fffffeL & l) == 0L) { 260 break; 261 } 262 if (kind > 17) { 263 kind = 17; 264 } 265 jjCheckNAddTwoStates(8, 9); 266 break; 267 case 4: 268 if ((0x2000000020L & l) != 0L) { 269 jjAddStates(16, 17); 270 } 271 break; 272 case 7: 273 if ((0x5000000050L & l) != 0L && kind > 16) { 274 kind = 16; 275 } 276 break; 277 case 9: 278 if ((0x7fffffe87fffffeL & l) == 0L) { 279 break; 280 } 281 if (kind > 17) { 282 kind = 17; 283 } 284 jjCheckNAdd(9); 285 break; 286 case 11: 287 if ((0x7fffffe87fffffeL & l) == 0L) { 288 break; 289 } 290 if (kind > 19) { 291 kind = 19; 292 } 293 jjCheckNAddTwoStates(11, 12); 294 break; 295 case 12: 296 if ((0x7fffffe87fffffeL & l) == 0L) { 297 break; 298 } 299 if (kind > 19) { 300 kind = 19; 301 } 302 jjCheckNAdd(12); 303 break; 304 case 17: 305 if ((0x2000000020L & l) != 0L) { 306 jjAddStates(18, 19); 307 } 308 break; 309 case 21: 310 if ((0x2000000020L & l) != 0L) { 311 jjAddStates(20, 21); 312 } 313 break; 314 case 25: 315 if ((0x2000000020L & l) != 0L) { 316 jjAddStates(22, 23); 317 } 318 break; 319 default: 320 break; 321 } 322 } while (i != startsAt); 323 } else { 324 int i2 = (curChar & 0xff) >> 6; 325 long l2 = 1L << (curChar & 077); 326 do { 327 switch (jjstateSet[--i]) { 328 default: 329 break; 330 } 331 } while (i != startsAt); 332 } 333 if (kind != 0x7fffffff) { 334 jjmatchedKind = kind; 335 jjmatchedPos = curPos; 336 kind = 0x7fffffff; 337 } 338 ++curPos; 339 if ((i = jjnewStateCnt) == (startsAt = 28 340 - (jjnewStateCnt = startsAt))) { 341 return curPos; 342 } 343 try { 344 curChar = input_stream.readChar(); 345 } catch (java.io.IOException e) { 346 return curPos; 347 } 348 } 349 } 350 351 static final int[] jjnextStates = { 14, 15, 20, 21, 24, 25, 7, 3, 4, 7, 16, 352 17, 7, 24, 25, 7, 5, 6, 18, 19, 22, 23, 26, 27, }; 353 354 /** Token literal values. */ 355 public static final String[] jjstrLiteralImages = { "", null, null, null, 356 null, "\53", "\55", "\52", "\57", "\136", "\75", "\74", "\44", 357 "\73", null, null, null, null, null, null, "\50", "\51", }; 358 359 /** Lexer state names. */ 360 public static final String[] lexStateNames = { "DEFAULT", }; 361 static final long[] jjtoToken = { 0x3b7fe1L, }; 362 static final long[] jjtoSkip = { 0x1eL, }; 363 protected SimpleCharStream input_stream; 364 private final int[] jjrounds = new int[28]; 365 private final int[] jjstateSet = new int[56]; 366 protected char curChar; 367 368 /** Constructor. */ 369 public UParserTokenManager(SimpleCharStream stream) { 370 if (SimpleCharStream.staticFlag) { 371 throw new Error( 372 "ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); 373 } 374 input_stream = stream; 375 } 376 377 /** Constructor. */ 378 public UParserTokenManager(SimpleCharStream stream, int lexState) { 379 this(stream); 380 SwitchTo(lexState); 381 } 382 383 /** Reinitialise parser. */ 384 public void ReInit(SimpleCharStream stream) { 385 jjmatchedPos = jjnewStateCnt = 0; 386 curLexState = defaultLexState; 387 input_stream = stream; 388 ReInitRounds(); 389 } 390 391 private void ReInitRounds() { 392 int i; 393 jjround = 0x80000001; 394 for (i = 28; i-- > 0;) { 395 jjrounds[i] = 0x80000000; 396 } 397 } 398 399 /** Reinitialise parser. */ 400 public void ReInit(SimpleCharStream stream, int lexState) { 401 ReInit(stream); 402 SwitchTo(lexState); 403 } 404 405 /** Switch to specified lex state. */ 406 public void SwitchTo(int lexState) { 407 if (lexState >= 1 || lexState < 0) { 408 throw new TokenMgrError( 409 "Error: Ignoring invalid lexical state : " + lexState 410 + ". State unchanged.", 411 TokenMgrError.INVALID_LEXICAL_STATE); 412 } else { 413 curLexState = lexState; 414 } 415 } 416 417 protected Token jjFillToken() { 418 final Token t; 419 final String curTokenImage; 420 final int beginLine; 421 final int endLine; 422 final int beginColumn; 423 final int endColumn; 424 String im = jjstrLiteralImages[jjmatchedKind]; 425 curTokenImage = (im == null) ? input_stream.GetImage() : im; 426 beginLine = input_stream.getBeginLine(); 427 beginColumn = input_stream.getBeginColumn(); 428 endLine = input_stream.getEndLine(); 429 endColumn = input_stream.getEndColumn(); 430 t = Token.newToken(jjmatchedKind, curTokenImage); 431 432 t.beginLine = beginLine; 433 t.endLine = endLine; 434 t.beginColumn = beginColumn; 435 t.endColumn = endColumn; 436 437 return t; 438 } 439 440 int curLexState = 0; 441 int defaultLexState = 0; 442 int jjnewStateCnt; 443 int jjround; 444 int jjmatchedPos; 445 int jjmatchedKind; 446 447 /** Get the next Token. */ 448 public Token getNextToken() { 449 Token matchedToken; 450 int curPos = 0; 451 452 EOFLoop: for (;;) { 453 try { 454 curChar = input_stream.BeginToken(); 455 } catch (java.io.IOException e) { 456 jjmatchedKind = 0; 457 matchedToken = jjFillToken(); 458 return matchedToken; 459 } 460 461 try { 462 input_stream.backup(0); 463 while (curChar <= 32 464 && (0x100002600L & (1L << curChar)) != 0L) { 465 curChar = input_stream.BeginToken(); 466 } 467 } catch (java.io.IOException e1) { 468 continue EOFLoop; 469 } 470 jjmatchedKind = 0x7fffffff; 471 jjmatchedPos = 0; 472 curPos = jjMoveStringLiteralDfa0_0(); 473 if (jjmatchedKind != 0x7fffffff) { 474 if (jjmatchedPos + 1 < curPos) { 475 input_stream.backup(curPos - jjmatchedPos - 1); 476 } 477 if ((jjtoToken[jjmatchedKind >> 6] 478 & (1L << (jjmatchedKind & 077))) != 0L) { 479 matchedToken = jjFillToken(); 480 return matchedToken; 481 } else { 482 continue EOFLoop; 483 } 484 } 485 int error_line = input_stream.getEndLine(); 486 int error_column = input_stream.getEndColumn(); 487 String error_after = null; 488 boolean EOFSeen = false; 489 try { 490 input_stream.readChar(); 491 input_stream.backup(1); 492 } catch (java.io.IOException e1) { 493 EOFSeen = true; 494 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 495 if (curChar == '\n' || curChar == '\r') { 496 error_line++; 497 error_column = 0; 498 } else { 499 error_column++; 500 } 501 } 502 if (!EOFSeen) { 503 input_stream.backup(1); 504 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 505 } 506 throw new TokenMgrError(EOFSeen, curLexState, error_line, 507 error_column, error_after, curChar, 508 TokenMgrError.LEXICAL_ERROR); 509 } 510 } 511 512 private void jjCheckNAdd(int state) { 513 if (jjrounds[state] != jjround) { 514 jjstateSet[jjnewStateCnt++] = state; 515 jjrounds[state] = jjround; 516 } 517 } 518 519 private void jjAddStates(int start, int end) { 520 do { 521 jjstateSet[jjnewStateCnt++] = jjnextStates[start]; 522 } while (start++ != end); 523 } 524 525 private void jjCheckNAddTwoStates(int state1, int state2) { 526 jjCheckNAdd(state1); 527 jjCheckNAdd(state2); 528 } 529 530 private void jjCheckNAddStates(int start, int end) { 531 do { 532 jjCheckNAdd(jjnextStates[start]); 533 } while (start++ != end); 534 } 535 536}