1 /* 2 * A n t l r T r a n s l a t i o n H e a d e r 3 * 4 * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001 5 * Purdue University Electrical Engineering 6 * With AHPCRC, University of Minnesota 7 * ANTLR Version 1.33MR33 8 * 9 * ..\bin\antlr dlg_p.g -gh 10 * 11 */ 12 13 #define ANTLR_VERSION 13333 14 #include "pcctscfg.h" 15 #include "pccts_stdio.h" 16 17 #include <ctype.h> 18 #include "dlg.h" 19 #define zzSET_SIZE 8 20 #include "antlr.h" 21 #include "tokens.h" 22 #include "dlgdef.h" 23 #include "mode.h" 24 25 /* MR23 In order to remove calls to PURIFY use the antlr -nopurify option */ 26 27 #ifndef PCCTS_PURIFY 28 #define PCCTS_PURIFY(r,s) memset((char *) &(r),'\0',(s)); 29 #endif 30 31 ANTLR_INFO 32 33 34 /* MR20 G. Hobbelt 35 Fix for Borland C++ 4.x & 5.x compiling with ALL warnings enabled 36 */ 37 38 #ifdef __TURBOC__ 39 #pragma warn -aus /* unused assignment of 'xxx' */ 40 #endif 41 42 int action_no = 0; /* keep track of actions outputted */ 43 int nfa_allocated = 0; /* keeps track of number of nfa nodes */ 44 nfa_node **nfa_array = NULL;/* root of binary tree that stores nfa array */ 45 nfa_node nfa_model_node; /* model to initialize new nodes */ 46 set used_chars; /* used to label trans. arcs */ 47 set used_classes; /* classes or chars used to label trans. arcs */ 48 set normal_chars; /* mask to get rid elements that aren't used 49 in set */ 50 int flag_paren = FALSE; 51 int flag_brace = FALSE; 52 int mode_counter = 0; /* keep track of number of %%names */ 53 54 55 56 void 57 #ifdef __USE_PROTOS 58 grammar(void) 59 #else 60 grammar() 61 #endif 62 { 63 zzRULE; 64 zzBLOCK(zztasp1); 65 zzMake0; 66 { 67 p_head(); p_class_hdr(); func_action = FALSE; 68 { 69 zzBLOCK(zztasp2); 70 zzMake0; 71 { 72 while ( (setwd1[LA(1)]&0x1) ) { 73 { 74 zzBLOCK(zztasp3); 75 zzMake0; 76 { 77 if ( (LA(1)==LEXACTION) ) { 78 zzmatch(LEXACTION); zzCONSUME; 79 } 80 else { 81 if ( (LA(1)==LEXMEMBER) ) { 82 zzmatch(LEXMEMBER); zzCONSUME; 83 } 84 else { 85 if ( (LA(1)==LEXPREFIX) ) { 86 zzmatch(LEXPREFIX); zzCONSUME; 87 } 88 else { 89 if ( (LA(1)==PARSERCLASS) ) { 90 zzmatch(PARSERCLASS); zzCONSUME; 91 } 92 else { 93 if ( (LA(1)==ACTION) ) { 94 } 95 else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 96 } 97 } 98 } 99 } 100 zzEXIT(zztasp3); 101 } 102 } 103 zzmatch(ACTION); zzCONSUME; 104 zzLOOP(zztasp2); 105 } 106 zzEXIT(zztasp2); 107 } 108 } 109 if ( gen_cpp ) p_includes(); 110 start_states(); 111 func_action = FALSE; p_tables(); p_tail(); 112 { 113 zzBLOCK(zztasp2); 114 zzMake0; 115 { 116 while ( (LA(1)==ACTION) ) { 117 zzmatch(ACTION); zzCONSUME; 118 zzLOOP(zztasp2); 119 } 120 zzEXIT(zztasp2); 121 } 122 } 123 zzmatch(1); 124 if (firstLexMember != 0) p_class_def1(); 125 zzCONSUME; 126 127 zzEXIT(zztasp1); 128 return; 129 fail: 130 zzEXIT(zztasp1); 131 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 132 zzresynch(setwd1, 0x2); 133 } 134 } 135 136 void 137 #ifdef __USE_PROTOS 138 start_states(void) 139 #else 140 start_states() 141 #endif 142 { 143 zzRULE; 144 zzBLOCK(zztasp1); 145 zzMake0; 146 { 147 { 148 zzBLOCK(zztasp2); 149 zzMake0; 150 { 151 if ( (LA(1)==PER_PER) ) { 152 zzmatch(PER_PER); zzCONSUME; 153 do_conversion(); 154 } 155 else { 156 if ( (LA(1)==NAME_PER_PER) ) { 157 zzmatch(NAME_PER_PER); zzCONSUME; 158 do_conversion(); 159 { 160 zzBLOCK(zztasp3); 161 zzMake0; 162 { 163 while ( (LA(1)==NAME_PER_PER) ) { 164 zzmatch(NAME_PER_PER); zzCONSUME; 165 do_conversion(); 166 zzLOOP(zztasp3); 167 } 168 zzEXIT(zztasp3); 169 } 170 } 171 } 172 else {zzFAIL(1,zzerr2,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 173 } 174 zzEXIT(zztasp2); 175 } 176 } 177 zzmatch(PER_PER); zzCONSUME; 178 zzEXIT(zztasp1); 179 return; 180 fail: 181 zzEXIT(zztasp1); 182 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 183 zzresynch(setwd1, 0x4); 184 } 185 } 186 187 void 188 #ifdef __USE_PROTOS 189 do_conversion(void) 190 #else 191 do_conversion() 192 #endif 193 { 194 zzRULE; 195 zzBLOCK(zztasp1); 196 zzMake0; 197 { 198 new_automaton_mode(); func_action = TRUE; 199 rule_list(); 200 201 dfa_class_nop[mode_counter] = 202 relabel(zzaArg(zztasp1,1 ).l,comp_level); 203 if (comp_level) 204 p_shift_table(mode_counter); 205 dfa_basep[mode_counter] = dfa_allocated+1; 206 make_dfa_model_node(dfa_class_nop[mode_counter]); 207 nfa_to_dfa(zzaArg(zztasp1,1 ).l); 208 ++mode_counter; 209 func_action = FALSE; 210 #ifdef HASH_STAT 211 fprint_hash_stats(stderr); 212 #endif 213 zzEXIT(zztasp1); 214 return; 215 fail: 216 zzEXIT(zztasp1); 217 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 218 zzresynch(setwd1, 0x8); 219 } 220 } 221 222 void 223 #ifdef __USE_PROTOS 224 rule_list(void) 225 #else 226 rule_list() 227 #endif 228 { 229 zzRULE; 230 zzBLOCK(zztasp1); 231 zzMake0; 232 { 233 if ( (setwd1[LA(1)]&0x10) ) { 234 rule(); 235 zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; 236 { 237 zzBLOCK(zztasp2); 238 zzMake0; 239 { 240 while ( (setwd1[LA(1)]&0x20) ) { 241 rule(); 242 {nfa_node *t1; 243 t1 = new_nfa_node(); 244 (t1)->trans[0]=zzaRet.l; 245 (t1)->trans[1]=zzaArg(zztasp2,1 ).l; 246 /* all accept nodes "dead ends" */ 247 zzaRet.l=t1; zzaRet.r=NULL; 248 } 249 zzLOOP(zztasp2); 250 } 251 zzEXIT(zztasp2); 252 } 253 } 254 } 255 else { 256 if ( (setwd1[LA(1)]&0x40) ) { 257 zzaRet.l = new_nfa_node(); zzaRet.r = NULL; 258 warning("no regular expressions", zzline); 259 } 260 else {zzFAIL(1,zzerr3,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 261 } 262 zzEXIT(zztasp1); 263 return; 264 fail: 265 zzEXIT(zztasp1); 266 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 267 zzresynch(setwd1, 0x80); 268 } 269 } 270 271 void 272 #ifdef __USE_PROTOS 273 rule(void) 274 #else 275 rule() 276 #endif 277 { 278 zzRULE; 279 zzBLOCK(zztasp1); 280 zzMake0; 281 { 282 if ( (setwd2[LA(1)]&0x1) ) { 283 reg_expr(); 284 zzmatch(ACTION); 285 if (zzaArg(zztasp1,1 ).r != NULL) { 286 zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; (zzaArg(zztasp1,1 ).r)->accept=action_no; 287 } 288 zzCONSUME; 289 290 } 291 else { 292 if ( (LA(1)==ACTION) ) { 293 zzmatch(ACTION); 294 zzaRet.l = NULL; zzaRet.r = NULL; 295 error("no expression for action ", zzline); 296 zzCONSUME; 297 298 } 299 else {zzFAIL(1,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 300 } 301 zzEXIT(zztasp1); 302 return; 303 fail: 304 zzEXIT(zztasp1); 305 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 306 zzresynch(setwd2, 0x2); 307 } 308 } 309 310 void 311 #ifdef __USE_PROTOS 312 reg_expr(void) 313 #else 314 reg_expr() 315 #endif 316 { 317 zzRULE; 318 zzBLOCK(zztasp1); 319 zzMake0; 320 { 321 and_expr(); 322 zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; 323 { 324 zzBLOCK(zztasp2); 325 zzMake0; 326 { 327 while ( (LA(1)==OR) ) { 328 zzmatch(OR); zzCONSUME; 329 and_expr(); 330 {nfa_node *t1, *t2; 331 t1 = new_nfa_node(); t2 = new_nfa_node(); 332 (t1)->trans[0]=zzaRet.l; 333 (t1)->trans[1]=zzaArg(zztasp2,2 ).l; 334 /* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[1]=t2; 335 if (zzaArg(zztasp2,2 ).r) { 336 (zzaArg(zztasp2,2 ).r)->trans[1]=t2; /* MR20 */ 337 } 338 zzaRet.l=t1; zzaRet.r=t2; 339 } 340 zzLOOP(zztasp2); 341 } 342 zzEXIT(zztasp2); 343 } 344 } 345 zzEXIT(zztasp1); 346 return; 347 fail: 348 zzEXIT(zztasp1); 349 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 350 zzresynch(setwd2, 0x4); 351 } 352 } 353 354 void 355 #ifdef __USE_PROTOS 356 and_expr(void) 357 #else 358 and_expr() 359 #endif 360 { 361 zzRULE; 362 zzBLOCK(zztasp1); 363 zzMake0; 364 { 365 repeat_expr(); 366 367 zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; 368 { 369 zzBLOCK(zztasp2); 370 zzMake0; 371 { 372 while ( (setwd2[LA(1)]&0x8) ) { 373 repeat_expr(); 374 if (zzaRet.r != NULL) { 375 (zzaRet.r)->trans[1]=zzaArg(zztasp2,1 ).l; 376 zzaRet.r=zzaArg(zztasp2,1 ).r; 377 } 378 zzLOOP(zztasp2); 379 } 380 zzEXIT(zztasp2); 381 } 382 } 383 zzEXIT(zztasp1); 384 return; 385 fail: 386 zzEXIT(zztasp1); 387 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 388 zzresynch(setwd2, 0x10); 389 } 390 } 391 392 void 393 #ifdef __USE_PROTOS 394 repeat_expr(void) 395 #else 396 repeat_expr() 397 #endif 398 { 399 zzRULE; 400 zzBLOCK(zztasp1); 401 zzMake0; 402 { 403 if ( (setwd2[LA(1)]&0x20) ) { 404 expr(); 405 zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; 406 { 407 zzBLOCK(zztasp2); 408 zzMake0; 409 { 410 if ( (LA(1)==ZERO_MORE) ) { 411 zzmatch(ZERO_MORE); 412 { nfa_node *t1,*t2; 413 /* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[0] = zzaRet.l; 414 t1 = new_nfa_node(); t2 = new_nfa_node(); 415 t1->trans[0]=zzaRet.l; 416 t1->trans[1]=t2; 417 /* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[1]=t2; 418 zzaRet.l=t1;zzaRet.r=t2; 419 } 420 zzCONSUME; 421 422 } 423 else { 424 if ( (LA(1)==ONE_MORE) ) { 425 zzmatch(ONE_MORE); 426 if (zzaRet.r != NULL) (zzaRet.r)->trans[0] = zzaRet.l; 427 zzCONSUME; 428 429 } 430 else { 431 if ( (setwd2[LA(1)]&0x40) ) { 432 } 433 else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 434 } 435 } 436 zzEXIT(zztasp2); 437 } 438 } 439 } 440 else { 441 if ( (LA(1)==ZERO_MORE) ) { 442 zzmatch(ZERO_MORE); 443 error("no expression for *", zzline); 444 zzCONSUME; 445 446 } 447 else { 448 if ( (LA(1)==ONE_MORE) ) { 449 zzmatch(ONE_MORE); 450 error("no expression for +", zzline); 451 zzCONSUME; 452 453 } 454 else {zzFAIL(1,zzerr6,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 455 } 456 } 457 zzEXIT(zztasp1); 458 return; 459 fail: 460 zzEXIT(zztasp1); 461 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 462 zzresynch(setwd2, 0x80); 463 } 464 } 465 466 void 467 #ifdef __USE_PROTOS 468 expr(void) 469 #else 470 expr() 471 #endif 472 { 473 zzRULE; 474 zzBLOCK(zztasp1); 475 zzMake0; 476 { 477 zzaRet.l = new_nfa_node(); 478 zzaRet.r = new_nfa_node(); 479 if ( (LA(1)==L_BRACK) ) { 480 zzmatch(L_BRACK); zzCONSUME; 481 atom_list(); 482 zzmatch(R_BRACK); 483 484 /* MR23 */ if (zzaRet.l != NULL) { 485 (zzaRet.l)->trans[0] = zzaRet.r; 486 (zzaRet.l)->label = set_dup(zzaArg(zztasp1,2 ).label); 487 set_orin(&used_chars,(zzaRet.l)->label); 488 } 489 zzCONSUME; 490 491 } 492 else { 493 if ( (LA(1)==NOT) ) { 494 zzmatch(NOT); zzCONSUME; 495 zzmatch(L_BRACK); zzCONSUME; 496 atom_list(); 497 zzmatch(R_BRACK); 498 499 /* MR23 */ if (zzaRet.l != NULL) { 500 (zzaRet.l)->trans[0] = zzaRet.r; 501 (zzaRet.l)->label = set_dif(normal_chars,zzaArg(zztasp1,3 ).label); 502 set_orin(&used_chars,(zzaRet.l)->label); 503 } 504 zzCONSUME; 505 506 } 507 else { 508 if ( (LA(1)==L_PAR) ) { 509 zzmatch(L_PAR); zzCONSUME; 510 reg_expr(); 511 zzmatch(R_PAR); 512 513 /* MR23 */ if (zzaRet.l != NULL) { 514 (zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l; 515 if (zzaArg(zztasp1,2 ).r) { 516 (zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r; /* MR20 */ 517 } 518 } 519 zzCONSUME; 520 521 } 522 else { 523 if ( (LA(1)==L_BRACE) ) { 524 zzmatch(L_BRACE); zzCONSUME; 525 reg_expr(); 526 zzmatch(R_BRACE); 527 528 /* MR23 */ if (zzaRet.l != NULL) { 529 (zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l; 530 (zzaRet.l)->trans[1] = zzaRet.r; 531 if (zzaArg(zztasp1,2 ).r) { 532 (zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r; /* MR20 */ 533 } 534 } 535 zzCONSUME; 536 537 } 538 else { 539 if ( (setwd3[LA(1)]&0x1) ) { 540 atom(); 541 542 /* MR23 */ if (zzaRet.l != NULL) { 543 (zzaRet.l)->trans[0] = zzaRet.r; 544 (zzaRet.l)->label = set_dup(zzaArg(zztasp1,1 ).label); 545 set_orin(&used_chars,(zzaRet.l)->label); 546 } 547 } 548 else {zzFAIL(1,zzerr7,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 549 } 550 } 551 } 552 } 553 zzEXIT(zztasp1); 554 return; 555 fail: 556 zzEXIT(zztasp1); 557 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 558 zzresynch(setwd3, 0x2); 559 } 560 } 561 562 void 563 #ifdef __USE_PROTOS 564 atom_list(void) 565 #else 566 atom_list() 567 #endif 568 { 569 zzRULE; 570 zzBLOCK(zztasp1); 571 zzMake0; 572 { 573 set_free(zzaRet.label); 574 { 575 zzBLOCK(zztasp2); 576 zzMake0; 577 { 578 while ( (setwd3[LA(1)]&0x4) ) { 579 near_atom(); 580 set_orin(&(zzaRet.label),zzaArg(zztasp2,1 ).label); 581 zzLOOP(zztasp2); 582 } 583 zzEXIT(zztasp2); 584 } 585 } 586 zzEXIT(zztasp1); 587 return; 588 fail: 589 zzEXIT(zztasp1); 590 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 591 zzresynch(setwd3, 0x8); 592 } 593 } 594 595 void 596 #ifdef __USE_PROTOS 597 near_atom(void) 598 #else 599 near_atom() 600 #endif 601 { 602 zzRULE; 603 zzBLOCK(zztasp1); 604 zzMake0; 605 { 606 register int i; 607 register int i_prime; 608 anychar(); 609 zzaRet.letter=zzaArg(zztasp1,1 ).letter; zzaRet.label=set_of(zzaArg(zztasp1,1 ).letter); 610 i_prime = zzaArg(zztasp1,1 ).letter + MIN_CHAR; 611 if (case_insensitive && islower(i_prime)) 612 set_orel(toupper(i_prime)-MIN_CHAR, 613 &(zzaRet.label)); 614 if (case_insensitive && isupper(i_prime)) 615 set_orel(tolower(i_prime)-MIN_CHAR, 616 &(zzaRet.label)); 617 { 618 zzBLOCK(zztasp2); 619 zzMake0; 620 { 621 if ( (LA(1)==RANGE) ) { 622 zzmatch(RANGE); zzCONSUME; 623 anychar(); 624 if (case_insensitive){ 625 i_prime = zzaRet.letter+MIN_CHAR; 626 zzaRet.letter = (islower(i_prime) ? 627 toupper(i_prime) : i_prime)-MIN_CHAR; 628 i_prime = zzaArg(zztasp2,2 ).letter+MIN_CHAR; 629 zzaArg(zztasp2,2 ).letter = (islower(i_prime) ? 630 toupper(i_prime) : i_prime)-MIN_CHAR; 631 } 632 /* check to see if range okay */ 633 { 634 int debugLetter1 = zzaRet.letter; 635 int debugLetter2 = zzaArg(zztasp2,2 ).letter; 636 } 637 if (zzaRet.letter > zzaArg(zztasp2,2 ).letter 638 && zzaArg(zztasp2,2 ).letter != 0xff){ /* MR16 */ 639 error("invalid range ", zzline); 640 } 641 for (i=zzaRet.letter; i<= (int)zzaArg(zztasp2,2 ).letter; ++i){ 642 set_orel(i,&(zzaRet.label)); 643 i_prime = i+MIN_CHAR; 644 if (case_insensitive && islower(i_prime)) 645 set_orel(toupper(i_prime)-MIN_CHAR, 646 &(zzaRet.label)); 647 if (case_insensitive && isupper(i_prime)) 648 set_orel(tolower(i_prime)-MIN_CHAR, 649 &(zzaRet.label)); 650 } 651 } 652 else { 653 if ( (setwd3[LA(1)]&0x10) ) { 654 } 655 else {zzFAIL(1,zzerr8,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 656 } 657 zzEXIT(zztasp2); 658 } 659 } 660 zzEXIT(zztasp1); 661 return; 662 fail: 663 zzEXIT(zztasp1); 664 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 665 zzresynch(setwd3, 0x20); 666 } 667 } 668 669 void 670 #ifdef __USE_PROTOS 671 atom(void) 672 #else 673 atom() 674 #endif 675 { 676 zzRULE; 677 zzBLOCK(zztasp1); 678 zzMake0; 679 { 680 register int i_prime; 681 anychar(); 682 zzaRet.label = set_of(zzaArg(zztasp1,1 ).letter); 683 i_prime = zzaArg(zztasp1,1 ).letter + MIN_CHAR; 684 if (case_insensitive && islower(i_prime)) 685 set_orel(toupper(i_prime)-MIN_CHAR, 686 &(zzaRet.label)); 687 if (case_insensitive && isupper(i_prime)) 688 set_orel(tolower(i_prime)-MIN_CHAR, 689 &(zzaRet.label)); 690 zzEXIT(zztasp1); 691 return; 692 fail: 693 zzEXIT(zztasp1); 694 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 695 zzresynch(setwd3, 0x40); 696 } 697 } 698 699 void 700 #ifdef __USE_PROTOS 701 anychar(void) 702 #else 703 anychar() 704 #endif 705 { 706 zzRULE; 707 zzBLOCK(zztasp1); 708 zzMake0; 709 { 710 if ( (LA(1)==REGCHAR) ) { 711 zzmatch(REGCHAR); 712 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 713 zzCONSUME; 714 715 } 716 else { 717 if ( (LA(1)==OCTAL_VALUE) ) { 718 zzmatch(OCTAL_VALUE); 719 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 720 zzCONSUME; 721 722 } 723 else { 724 if ( (LA(1)==HEX_VALUE) ) { 725 zzmatch(HEX_VALUE); 726 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 727 zzCONSUME; 728 729 } 730 else { 731 if ( (LA(1)==DEC_VALUE) ) { 732 zzmatch(DEC_VALUE); 733 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 734 zzCONSUME; 735 736 } 737 else { 738 if ( (LA(1)==TAB) ) { 739 zzmatch(TAB); 740 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 741 zzCONSUME; 742 743 } 744 else { 745 if ( (LA(1)==NL) ) { 746 zzmatch(NL); 747 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 748 zzCONSUME; 749 750 } 751 else { 752 if ( (LA(1)==CR) ) { 753 zzmatch(CR); 754 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 755 zzCONSUME; 756 757 } 758 else { 759 if ( (LA(1)==BS) ) { 760 zzmatch(BS); 761 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 762 zzCONSUME; 763 764 } 765 else { 766 if ( (LA(1)==LIT) ) { 767 zzmatch(LIT); 768 zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR; 769 zzCONSUME; 770 771 } 772 else { 773 if ( (LA(1)==L_EOF) ) { 774 zzmatch(L_EOF); 775 zzaRet.letter = 0; 776 zzCONSUME; 777 778 } 779 else {zzFAIL(1,zzerr9,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} 780 } 781 } 782 } 783 } 784 } 785 } 786 } 787 } 788 } 789 zzEXIT(zztasp1); 790 return; 791 fail: 792 zzEXIT(zztasp1); 793 /* empty action */ 794 zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); 795 zzresynch(setwd3, 0x80); 796 } 797 } 798 799 /* adds a new nfa to the binary tree and returns a pointer to it */ 800 nfa_node * 801 #ifdef __USE_PROTOS 802 new_nfa_node(void) 803 #else 804 new_nfa_node() 805 #endif 806 { 807 register nfa_node *t; 808 static int nfa_size=0; /* elements nfa_array[] can hold */ 809 810 ++nfa_allocated; 811 if (nfa_size<=nfa_allocated){ 812 /* need to redo array */ 813 if (!nfa_array){ 814 /* need some to do inital allocation */ 815 nfa_size=nfa_allocated+NFA_MIN; 816 nfa_array=(nfa_node **) malloc(sizeof(nfa_node*)* 817 nfa_size); 818 }else{ 819 /* need more space */ 820 nfa_size=2*(nfa_allocated+1); 821 nfa_array=(nfa_node **) realloc(nfa_array, 822 sizeof(nfa_node*)*nfa_size); 823 } 824 } 825 /* fill out entry in array */ 826 t = (nfa_node*) malloc(sizeof(nfa_node)); 827 nfa_array[nfa_allocated] = t; 828 *t = nfa_model_node; 829 t->node_no = nfa_allocated; 830 return t; 831 } 832 833 834 /* initialize the model node used to fill in newly made nfa_nodes */ 835 void 836 #ifdef __USE_PROTOS 837 make_nfa_model_node(void) 838 #else 839 make_nfa_model_node() 840 #endif 841 { 842 nfa_model_node.node_no = -1; /* impossible value for real nfa node */ 843 nfa_model_node.nfa_set = 0; 844 nfa_model_node.accept = 0; /* error state default*/ 845 nfa_model_node.trans[0] = NULL; 846 nfa_model_node.trans[1] = NULL; 847 nfa_model_node.label = empty; 848 } 849 850 #if defined(DEBUG) || defined(_DEBUG) 851 852 /* print out the pointer value and the node_number */ 853 void 854 #ifdef __USE_PROTOS 855 fprint_dfa_pair(FILE *f, nfa_node *p) 856 #else 857 fprint_dfa_pair(f, p) 858 FILE *f; 859 nfa_node *p; 860 #endif 861 { 862 if (p){ 863 fprintf(f, "%x (%d)", p, p->node_no); 864 }else{ 865 fprintf(f, "(nil)"); 866 } 867 } 868 869 /* print out interest information on a set */ 870 void 871 #ifdef __USE_PROTOS 872 fprint_set(FILE *f, set s) 873 #else 874 fprint_set(f,s) 875 FILE *f; 876 set s; 877 #endif 878 { 879 unsigned int *x; 880 881 fprintf(f, "n = %d,", s.n); 882 if (s.setword){ 883 fprintf(f, "setword = %x, ", s.setword); 884 /* print out all the elements in the set */ 885 x = set_pdq(s); 886 while (*x!=nil){ 887 fprintf(f, "%d ", *x); 888 ++x; 889 } 890 }else{ 891 fprintf(f, "setword = (nil)"); 892 } 893 } 894 895 /* code to be able to dump out the nfas 896 return 0 if okay dump 897 return 1 if screwed up 898 */ 899 int 900 #ifdef __USE_PROTOS 901 dump_nfas(int first_node, int last_node) 902 #else 903 dump_nfas(first_node, last_node) 904 int first_node; 905 int last_node; 906 #endif 907 { 908 register int i; 909 nfa_node *t; 910 911 for (i=first_node; i<=last_node; ++i){ 912 t = NFA(i); 913 if (!t) break; 914 fprintf(stderr, "nfa_node %d {\n", t->node_no); 915 fprintf(stderr, "\n\tnfa_set = %d\n", t->nfa_set); 916 fprintf(stderr, "\taccept\t=\t%d\n", t->accept); 917 fprintf(stderr, "\ttrans\t=\t("); 918 fprint_dfa_pair(stderr, t->trans[0]); 919 fprintf(stderr, ","); 920 fprint_dfa_pair(stderr, t->trans[1]); 921 fprintf(stderr, ")\n"); 922 fprintf(stderr, "\tlabel\t=\t{ "); 923 fprint_set(stderr, t->label); 924 fprintf(stderr, "\t}\n"); 925 fprintf(stderr, "}\n\n"); 926 } 927 return 0; 928 } 929 #endif 930 931 /* DLG-specific syntax error message generator 932 * (define USER_ZZSYN when compiling so don't get 2 definitions) 933 */ 934 void 935 #ifdef __USE_PROTOS 936 zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok, int k, char *bad_text) 937 #else 938 zzsyn(text, tok, egroup, eset, etok, k, bad_text) 939 char *text, *egroup, *bad_text; 940 int tok; 941 int etok; 942 int k; 943 SetWordType *eset; 944 #endif 945 { 946 fprintf(stderr, ErrHdr, file_str[0]!=NULL?file_str[0]:"stdin", zzline); 947 fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text); 948 if ( !etok && !eset ) {fprintf(stderr, "\n"); return;} 949 if ( k==1 ) fprintf(stderr, " missing"); 950 else 951 { 952 fprintf(stderr, "; \"%s\" not", bad_text); 953 if ( zzset_deg(eset)>1 ) fprintf(stderr, " in"); 954 } 955 if ( zzset_deg(eset)>0 ) zzedecode(eset); 956 else fprintf(stderr, " %s", zztokens[etok]); 957 if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup); 958 fprintf(stderr, "\n"); 959 } 960