1 19 package jxl.biff.formula; 20 24 import jxl.biff.WorkbookMethods; 25 26 27 class Yylex { 28 private final int YY_BUFFER_SIZE = 512; 29 private final int YY_F = -1; 30 private final int YY_NO_STATE = -1; 31 private final int YY_NOT_ACCEPT = 0; 32 private final int YY_START = 1; 33 private final int YY_END = 2; 34 private final int YY_NO_ANCHOR = 4; 35 private final int YY_BOL = 65536; 36 private final int YY_EOF = 65537; 37 38 int getPos() { return yychar ; } 39 40 private boolean emptyString; 41 42 private ExternalSheet externalSheet; 43 private WorkbookMethods nameTable; 44 void setExternalSheet(ExternalSheet es) 45 { 46 externalSheet = es; 47 } 48 void setNameTable(WorkbookMethods nt) 49 { 50 nameTable = nt; 51 } 52 private java.io.BufferedReader yy_reader; 53 private int yy_buffer_index; 54 private int yy_buffer_read; 55 private int yy_buffer_start; 56 private int yy_buffer_end; 57 private char yy_buffer[]; 58 private int yychar; 59 private int yyline; 60 private boolean yy_at_bol; 61 private int yy_lexical_state; 62 63 Yylex (java.io.Reader reader) { 64 this (); 65 if (null == reader) { 66 throw (new Error ("Error: Bad input stream initializer.")); 67 } 68 yy_reader = new java.io.BufferedReader (reader); 69 } 70 71 Yylex (java.io.InputStream instream) { 72 this (); 73 if (null == instream) { 74 throw (new Error ("Error: Bad input stream initializer.")); 75 } 76 yy_reader = new java.io.BufferedReader (new java.io.InputStreamReader (instream)); 77 } 78 79 private Yylex () { 80 yy_buffer = new char[YY_BUFFER_SIZE]; 81 yy_buffer_read = 0; 82 yy_buffer_index = 0; 83 yy_buffer_start = 0; 84 yy_buffer_end = 0; 85 yychar = 0; 86 yyline = 0; 87 yy_at_bol = true; 88 yy_lexical_state = YYINITIAL; 89 } 90 91 private boolean yy_eof_done = false; 92 private final int YYSTRING = 1; 93 private final int YYINITIAL = 0; 94 private final int yy_state_dtrans[] = { 95 0, 96 28 97 }; 98 private void yybegin (int state) { 99 yy_lexical_state = state; 100 } 101 private int yy_advance () 102 throws java.io.IOException { 103 int next_read; 104 int i; 105 int j; 106 107 if (yy_buffer_index < yy_buffer_read) { 108 return yy_buffer[yy_buffer_index++]; 109 } 110 111 if (0 != yy_buffer_start) { 112 i = yy_buffer_start; 113 j = 0; 114 while (i < yy_buffer_read) { 115 yy_buffer[j] = yy_buffer[i]; 116 ++i; 117 ++j; 118 } 119 yy_buffer_end = yy_buffer_end - yy_buffer_start; 120 yy_buffer_start = 0; 121 yy_buffer_read = j; 122 yy_buffer_index = j; 123 next_read = yy_reader.read(yy_buffer, 124 yy_buffer_read, 125 yy_buffer.length - yy_buffer_read); 126 if (-1 == next_read) { 127 return YY_EOF; 128 } 129 yy_buffer_read = yy_buffer_read + next_read; 130 } 131 132 while (yy_buffer_index >= yy_buffer_read) { 133 if (yy_buffer_index >= yy_buffer.length) { 134 yy_buffer = yy_double(yy_buffer); 135 } 136 next_read = yy_reader.read(yy_buffer, 137 yy_buffer_read, 138 yy_buffer.length - yy_buffer_read); 139 if (-1 == next_read) { 140 return YY_EOF; 141 } 142 yy_buffer_read = yy_buffer_read + next_read; 143 } 144 return yy_buffer[yy_buffer_index++]; 145 } 146 private void yy_move_end () { 147 if (yy_buffer_end > yy_buffer_start && 148 '\n' == yy_buffer[yy_buffer_end-1]) 149 yy_buffer_end--; 150 if (yy_buffer_end > yy_buffer_start && 151 '\r' == yy_buffer[yy_buffer_end-1]) 152 yy_buffer_end--; 153 } 154 private boolean yy_last_was_cr=false; 155 private void yy_mark_start () { 156 int i; 157 for (i = yy_buffer_start; i < yy_buffer_index; ++i) { 158 if ('\n' == yy_buffer[i] && !yy_last_was_cr) { 159 ++yyline; 160 } 161 if ('\r' == yy_buffer[i]) { 162 ++yyline; 163 yy_last_was_cr=true; 164 } else yy_last_was_cr=false; 165 } 166 yychar = yychar 167 + yy_buffer_index - yy_buffer_start; 168 yy_buffer_start = yy_buffer_index; 169 } 170 private void yy_mark_end () { 171 yy_buffer_end = yy_buffer_index; 172 } 173 private void yy_to_mark () { 174 yy_buffer_index = yy_buffer_end; 175 yy_at_bol = (yy_buffer_end > yy_buffer_start) && 176 ('\r' == yy_buffer[yy_buffer_end-1] || 177 '\n' == yy_buffer[yy_buffer_end-1] || 178 2028 == yy_buffer[yy_buffer_end-1] || 179 2029 == yy_buffer[yy_buffer_end-1]); 180 } 181 private java.lang.String yytext () { 182 return (new java.lang.String (yy_buffer, 183 yy_buffer_start, 184 yy_buffer_end - yy_buffer_start)); 185 } 186 private int yylength () { 187 return yy_buffer_end - yy_buffer_start; 188 } 189 private char[] yy_double (char buf[]) { 190 int i; 191 char newbuf[]; 192 newbuf = new char[2*buf.length]; 193 for (i = 0; i < buf.length; ++i) { 194 newbuf[i] = buf[i]; 195 } 196 return newbuf; 197 } 198 private final int YY_E_INTERNAL = 0; 199 private final int YY_E_MATCH = 1; 200 private java.lang.String yy_error_string[] = { 201 "Error: Internal error.\n", 202 "Error: Unmatched input.\n" 203 }; 204 private void yy_error (int code,boolean fatal) { 205 java.lang.System.out.print(yy_error_string[code]); 206 java.lang.System.out.flush(); 207 if (fatal) { 208 throw new Error ("Fatal Error.\n"); 209 } 210 } 211 private int[][] unpackFromString(int size1, int size2, String st) { 212 int colonIndex = -1; 213 String lengthString; 214 int sequenceLength = 0; 215 int sequenceInteger = 0; 216 217 int commaIndex; 218 String workString; 219 220 int res[][] = new int[size1][size2]; 221 for (int i= 0; i < size1; i++) { 222 for (int j= 0; j < size2; j++) { 223 if (sequenceLength != 0) { 224 res[i][j] = sequenceInteger; 225 sequenceLength--; 226 continue; 227 } 228 commaIndex = st.indexOf(','); 229 workString = (commaIndex==-1) ? st : 230 st.substring(0, commaIndex); 231 st = st.substring(commaIndex+1); 232 colonIndex = workString.indexOf(':'); 233 if (colonIndex == -1) { 234 res[i][j]=Integer.parseInt(workString); 235 continue; 236 } 237 lengthString = 238 workString.substring(colonIndex+1); 239 sequenceLength=Integer.parseInt(lengthString); 240 workString=workString.substring(0,colonIndex); 241 sequenceInteger=Integer.parseInt(workString); 242 res[i][j] = sequenceInteger; 243 sequenceLength--; 244 } 245 } 246 return res; 247 } 248 private int yy_acpt[] = { 249 YY_NOT_ACCEPT, 250 YY_NO_ANCHOR, 251 YY_NO_ANCHOR, 252 YY_NO_ANCHOR, 253 YY_NO_ANCHOR, 254 YY_NO_ANCHOR, 255 YY_NO_ANCHOR, 256 YY_NO_ANCHOR, 257 YY_NO_ANCHOR, 258 YY_NO_ANCHOR, 259 YY_NO_ANCHOR, 260 YY_NO_ANCHOR, 261 YY_NO_ANCHOR, 262 YY_NO_ANCHOR, 263 YY_NO_ANCHOR, 264 YY_NO_ANCHOR, 265 YY_NO_ANCHOR, 266 YY_NO_ANCHOR, 267 YY_NO_ANCHOR, 268 YY_NO_ANCHOR, 269 YY_NO_ANCHOR, 270 YY_NO_ANCHOR, 271 YY_NO_ANCHOR, 272 YY_NO_ANCHOR, 273 YY_NO_ANCHOR, 274 YY_NO_ANCHOR, 275 YY_NO_ANCHOR, 276 YY_NO_ANCHOR, 277 YY_NO_ANCHOR, 278 YY_NO_ANCHOR, 279 YY_NOT_ACCEPT, 280 YY_NO_ANCHOR, 281 YY_NO_ANCHOR, 282 YY_NO_ANCHOR, 283 YY_NO_ANCHOR, 284 YY_NO_ANCHOR, 285 YY_NOT_ACCEPT, 286 YY_NO_ANCHOR, 287 YY_NOT_ACCEPT, 288 YY_NO_ANCHOR, 289 YY_NOT_ACCEPT, 290 YY_NO_ANCHOR, 291 YY_NOT_ACCEPT, 292 YY_NOT_ACCEPT, 293 YY_NOT_ACCEPT, 294 YY_NOT_ACCEPT, 295 YY_NOT_ACCEPT, 296 YY_NOT_ACCEPT, 297 YY_NOT_ACCEPT, 298 YY_NOT_ACCEPT, 299 YY_NOT_ACCEPT, 300 YY_NOT_ACCEPT, 301 YY_NOT_ACCEPT, 302 YY_NOT_ACCEPT, 303 YY_NOT_ACCEPT, 304 YY_NOT_ACCEPT, 305 YY_NOT_ACCEPT, 306 YY_NOT_ACCEPT, 307 YY_NOT_ACCEPT, 308 YY_NOT_ACCEPT, 309 YY_NOT_ACCEPT, 310 YY_NOT_ACCEPT, 311 YY_NOT_ACCEPT, 312 YY_NOT_ACCEPT, 313 YY_NOT_ACCEPT, 314 YY_NOT_ACCEPT, 315 YY_NOT_ACCEPT, 316 YY_NOT_ACCEPT, 317 YY_NOT_ACCEPT, 318 YY_NOT_ACCEPT, 319 YY_NO_ANCHOR, 320 YY_NOT_ACCEPT, 321 YY_NO_ANCHOR, 322 YY_NOT_ACCEPT, 323 YY_NOT_ACCEPT, 324 YY_NO_ANCHOR, 325 YY_NOT_ACCEPT 326 }; 327 private int yy_cmap[] = unpackFromString(1,65538, 328 "29:8,14:3,29:21,14,16,28,15,11,15:2,13,26,27,3,1,8,2,10,4,9:10,17,15,7,6,5," + 329 "15:2,23,12:3,21,22,12:5,24,12:5,19,25,18,20,12:5,15:5,29,12:26,29,15,29,15," + 330 "29:65409,0:2")[0]; 331 332 private int yy_rmap[] = unpackFromString(1,77, 333 "0,1,2,1,2:2,3,2,4,2,5,2:2,1:3,2:3,6,7,1,8,9,10,11,10,12,13,1,14,15,10,16,17" + 334 ",18,19,20,21,22,23,24,8,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41," + 335 "11,42,43,44,45,46,47,12,48,17,49,50,51,2,52,53,54")[0]; 336 337 private int yy_nxt[][] = unpackFromString(55,30, 338 "1,2,3,4,5,6,7,8,9,10,30,36,30,38,11,73:2,12,71,30:3,76,30:3,13,14,15,-1:32," + 339 "73,-1,73:10,40,73:2,74,73:9,-1:5,73,-1,73:3,16,73:6,40,73:2,74,73:9,-1:5,73" + 340 ",-1,73:2,17,18,73:6,40,73:2,74,73:9,-1:5,73,-1,73:6,10,42,73:2,40,73:2,74,7" + 341 "3:9,-1:5,73,-1,73:6,19,73:3,40,73:2,74,48,73:8,-1:5,73,-1,73:6,31,32,43,32," + 342 "40,73:2,74,73,32:8,21,-1:4,73,-1,73:6,22,73:3,40,73:2,74,73:9,-1:5,73,-1,73" + 343 ":6,23,73:3,40,73:2,74,58,73:8,-1:5,73,-1,73:6,39,32,73,32,40,73:2,74,73,32:" + 344 "8,21,-1:4,73,-1,73:6,25,73:3,40,73:2,74,73:9,-1:5,73,-1,73:6,27,73:3,40,73:" + 345 "2,74,73:9,-1:4,1,35:27,29,35,-1,73,-1,73:6,19,20,43,20,40,73:2,74,73,20:8,2" + 346 "1,-1:4,73,-1,73:6,31,39,73,39,40,73:2,74,48,39:8,-1:13,33,-1:7,61,-1:21,34," + 347 "-1:21,35:27,-1,35,-1,73,-1,73:7,44,73,44,40,73:2,74,73,44:8,-1:5,73,-1,73:6" + 348 ",39,32,73,32,40,73:2,74,73,32:3,24,32:4,21,-1:4,73,-1,73:10,-1,73:12,-1:5,7" + 349 "3,-1,73:6,39:2,73,39,40,73:2,74,73,39:8,-1:20,45,-1:14,73,-1,73:6,39,32,73," + 350 "32,40,73:2,74,73,32:3,26,32:4,21,-1:4,73,-1,73:6,19,73:3,40,73:2,74,73:9,-1" + 351 ":5,73,-1,73:6,19,49,43,49,40,73:2,74,73,49:8,-1:14,50,51,50,-1:5,50:8,-1:5," + 352 "73,-1,73:6,23,52,53,52,40,73:2,74,73,52:8,-1:5,73,-1,73:7,46,73,46,40,73:2," + 353 "74,73,46:8,-1:5,73,-1,73:7,54,55,54,40,73:2,74,73,54:8,-1:5,73,-1,73:6,19,7" + 354 "3,43,73,40,73:2,74,73:9,-1:13,33,56,57,56,-1:5,56:8,-1:14,50,-1,50,-1:5,50:" + 355 "8,-1:5,73,-1,73:6,23,73,53,73,40,73:2,74,73:9,-1:5,73,-1,73:6,23,73:3,40,73" + 356 ":2,74,73:9,-1:5,73,-1,73:6,25,59,60,59,40,73:2,74,73,59:8,-1:5,73,-1,73:7,5" + 357 "4,73,54,40,73:2,74,73,54:8,-1:13,33,-1,57,-1:27,33,-1:21,73,-1,73:7,62,63,6" + 358 "2,40,73:2,74,73,62:8,-1:5,73,-1,73:6,25,73,60,73,40,73:2,74,73:9,-1:14,64,6" + 359 "5,64,-1:5,64:8,-1:5,73,-1,73:6,27,66,67,66,40,73:2,74,73,66:8,-1:5,73,-1,73" + 360 ":7,62,73,62,40,73:2,74,73,62:8,-1:13,34,68,69,68,-1:5,68:8,-1:14,64,-1,64,-" + 361 "1:5,64:8,-1:5,73,-1,73:6,27,73,67,73,40,73:2,74,73:9,-1:13,34,-1,69,-1:19,7" + 362 "3,-1,73:6,31,32,43,32,40,73:2,74,73,32:2,37,32:5,21,-1:4,73,-1,73:6,19,20,4" + 363 "3,20,40,73:2,74,73,20,70,20:6,21,-1:4,73,-1,73:6,39,32,73,32,40,73:2,74,73," + 364 "32:7,41,21,-1:4,73,-1,73:7,46,47,46,40,73:2,74,73,46:8,-1:5,73,-1,73:6,31,3" + 365 "2,43,32,40,73:2,74,73,32:6,72,32,21,-1:4,73,-1,73:6,19,20,43,20,40,73:2,74," + 366 "73,20:5,75,20:2,21,-1:3"); 367 368 public ParseItem yylex () 369 throws java.io.IOException , 370 jxl.biff.formula.FormulaException 371 372 { 373 int yy_lookahead; 374 int yy_anchor = YY_NO_ANCHOR; 375 int yy_state = yy_state_dtrans[yy_lexical_state]; 376 int yy_next_state = YY_NO_STATE; 377 int yy_last_accept_state = YY_NO_STATE; 378 boolean yy_initial = true; 379 int yy_this_accept; 380 381 yy_mark_start(); 382 yy_this_accept = yy_acpt[yy_state]; 383 if (YY_NOT_ACCEPT != yy_this_accept) { 384 yy_last_accept_state = yy_state; 385 yy_mark_end(); 386 } 387 while (true) { 388 if (yy_initial && yy_at_bol) yy_lookahead = YY_BOL; 389 else yy_lookahead = yy_advance(); 390 yy_next_state = YY_F; 391 yy_next_state = yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]]; 392 if (YY_EOF == yy_lookahead && true == yy_initial) { 393 return null; 394 } 395 if (YY_F != yy_next_state) { 396 yy_state = yy_next_state; 397 yy_initial = false; 398 yy_this_accept = yy_acpt[yy_state]; 399 if (YY_NOT_ACCEPT != yy_this_accept) { 400 yy_last_accept_state = yy_state; 401 yy_mark_end(); 402 } 403 } 404 else { 405 if (YY_NO_STATE == yy_last_accept_state) { 406 throw (new Error ("Lexical Error: Unmatched Input.")); 407 } 408 else { 409 yy_anchor = yy_acpt[yy_last_accept_state]; 410 if (0 != (YY_END & yy_anchor)) { 411 yy_move_end(); 412 } 413 yy_to_mark(); 414 switch (yy_last_accept_state) { 415 case 1: 416 417 case -2: 418 break; 419 case 2: 420 { return new Plus() ;} 421 case -3: 422 break; 423 case 3: 424 { return new Minus() ; } 425 case -4: 426 break; 427 case 4: 428 { return new Multiply() ; } 429 case -5: 430 break; 431 case 5: 432 { return new Divide() ; } 433 case -6: 434 break; 435 case 6: 436 { return new GreaterThan() ; } 437 case -7: 438 break; 439 case 7: 440 { return new Equal() ; } 441 case -8: 442 break; 443 case 8: 444 { return new LessThan() ; } 445 case -9: 446 break; 447 case 9: 448 { return new ArgumentSeparator() ; } 449 case -10: 450 break; 451 case 10: 452 { return new IntegerValue(yytext()) ; } 453 case -11: 454 break; 455 case 11: 456 {} 457 case -12: 458 break; 459 case 12: 460 { return new RangeSeparator(); } 461 case -13: 462 break; 463 case 13: 464 { return new OpenParentheses() ;} 465 case -14: 466 break; 467 case 14: 468 { return new CloseParentheses() ;} 469 case -15: 470 break; 471 case 15: 472 {emptyString = true; yybegin(YYSTRING);} 473 case -16: 474 break; 475 case 16: 476 { return new GreaterEqual() ; } 477 case -17: 478 break; 479 case 17: 480 { return new NotEqual() ; } 481 case -18: 482 break; 483 case 18: 484 { return new LessEqual() ; } 485 case -19: 486 break; 487 case 19: 488 { return new CellReference(yytext()) ; } 489 case -20: 490 break; 491 case 20: 492 {return new NameRange(yytext(), nameTable); } 493 case -21: 494 break; 495 case 21: 496 { return new StringFunction(yytext()) ; } 497 case -22: 498 break; 499 case 22: 500 { return new DoubleValue(yytext()) ; } 501 case -23: 502 break; 503 case 23: 504 { return new CellReference3d(yytext(),externalSheet) ; } 505 case -24: 506 break; 507 case 24: 508 {return new BooleanValue(yytext());} 509 case -25: 510 break; 511 case 25: 512 { return new Area(yytext()) ; } 513 case -26: 514 break; 515 case 26: 516 {return new BooleanValue(yytext());} 517 case -27: 518 break; 519 case 27: 520 { return new Area3d(yytext(),externalSheet) ; } 521 case -28: 522 break; 523 case 28: 524 {emptyString = false; return new StringValue(yytext()) ; } 525 case -29: 526 break; 527 case 29: 528 {yybegin(YYINITIAL); if (emptyString) return new StringValue("");} 529 case -30: 530 break; 531 case 31: 532 { return new CellReference(yytext()) ; } 533 case -31: 534 break; 535 case 32: 536 {return new NameRange(yytext(), nameTable); } 537 case -32: 538 break; 539 case 33: 540 { return new CellReference3d(yytext(),externalSheet) ; } 541 case -33: 542 break; 543 case 34: 544 { return new Area3d(yytext(),externalSheet) ; } 545 case -34: 546 break; 547 case 35: 548 {emptyString = false; return new StringValue(yytext()) ; } 549 case -35: 550 break; 551 case 37: 552 {return new NameRange(yytext(), nameTable); } 553 case -36: 554 break; 555 case 39: 556 {return new NameRange(yytext(), nameTable); } 557 case -37: 558 break; 559 case 41: 560 {return new NameRange(yytext(), nameTable); } 561 case -38: 562 break; 563 case 70: 564 {return new NameRange(yytext(), nameTable); } 565 case -39: 566 break; 567 case 72: 568 {return new NameRange(yytext(), nameTable); } 569 case -40: 570 break; 571 case 75: 572 {return new NameRange(yytext(), nameTable); } 573 case -41: 574 break; 575 default: 576 yy_error(YY_E_INTERNAL,false); 577 case -1: 578 } 579 yy_initial = true; 580 yy_state = yy_state_dtrans[yy_lexical_state]; 581 yy_next_state = YY_NO_STATE; 582 yy_last_accept_state = YY_NO_STATE; 583 yy_mark_start(); 584 yy_this_accept = yy_acpt[yy_state]; 585 if (YY_NOT_ACCEPT != yy_this_accept) { 586 yy_last_accept_state = yy_state; 587 yy_mark_end(); 588 } 589 } 590 } 591 } 592 } 593 } 594 | Popular Tags |