1 /* $NetBSD: gen.c,v 1.2 2016/01/09 17:38:57 christos Exp $ */ 2 3 /* gen - actual generation (writing) of flex scanners */ 4 5 /* Copyright (c) 1990 The Regents of the University of California. */ 6 /* All rights reserved. */ 7 8 /* This code is derived from software contributed to Berkeley by */ 9 /* Vern Paxson. */ 10 11 /* The United States Government has rights in this work pursuant */ 12 /* to contract no. DE-AC03-76SF00098 between the United States */ 13 /* Department of Energy and the University of California. */ 14 15 /* This file is part of flex. */ 16 17 /* Redistribution and use in source and binary forms, with or without */ 18 /* modification, are permitted provided that the following conditions */ 19 /* are met: */ 20 21 /* 1. Redistributions of source code must retain the above copyright */ 22 /* notice, this list of conditions and the following disclaimer. */ 23 /* 2. Redistributions in binary form must reproduce the above copyright */ 24 /* notice, this list of conditions and the following disclaimer in the */ 25 /* documentation and/or other materials provided with the distribution. */ 26 27 /* Neither the name of the University nor the names of its contributors */ 28 /* may be used to endorse or promote products derived from this software */ 29 /* without specific prior written permission. */ 30 31 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 32 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 33 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 34 /* PURPOSE. */ 35 #include "flexdef.h" 36 __RCSID("$NetBSD: gen.c,v 1.2 2016/01/09 17:38:57 christos Exp $"); 37 38 #include "tables.h" 39 40 41 /* declare functions that have forward references */ 42 43 void gen_next_state PROTO ((int)); 44 void genecs PROTO ((void)); 45 void indent_put2s PROTO ((const char *, const char *)); 46 void indent_puts PROTO ((const char *)); 47 48 49 static int indent_level = 0; /* each level is 8 spaces */ 50 51 #define indent_up() (++indent_level) 52 #define indent_down() (--indent_level) 53 #define set_indent(indent_val) indent_level = indent_val 54 55 /* Almost everything is done in terms of arrays starting at 1, so provide 56 * a null entry for the zero element of all C arrays. (The exception 57 * to this is that the fast table representation generally uses the 58 * 0 elements of its arrays, too.) 59 */ 60 61 static const char *get_int16_decl (void) 62 { 63 return (gentables) 64 ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n" 65 : "static yyconst flex_int16_t * %s = 0;\n"; 66 } 67 68 69 static const char *get_int32_decl (void) 70 { 71 return (gentables) 72 ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n" 73 : "static yyconst flex_int32_t * %s = 0;\n"; 74 } 75 76 static const char *get_state_decl (void) 77 { 78 return (gentables) 79 ? "static yyconst yy_state_type %s[%d] =\n { 0,\n" 80 : "static yyconst yy_state_type * %s = 0;\n"; 81 } 82 83 static const char *get_uint16_decl (void) 84 { 85 return (gentables) 86 ? "static yyconst flex_uint16_t %s[%d] =\n { 0,\n" 87 : "static yyconst flex_uint16_t * %s = 0;\n"; 88 } 89 90 static const char *get_uint32_decl (void) 91 { 92 return (gentables) 93 ? "static yyconst flex_uint32_t %s[%d] =\n { 0,\n" 94 : "static yyconst flex_uint32_t * %s = 0;\n"; 95 } 96 97 static const char *get_yy_char_decl (void) 98 { 99 return (gentables) 100 ? "static yyconst YY_CHAR %s[%d] =\n { 0,\n" 101 : "static yyconst YY_CHAR * %s = 0;\n"; 102 } 103 104 /* Indent to the current level. */ 105 106 void do_indent (void) 107 { 108 int i = indent_level * 8; 109 110 while (i >= 8) { 111 outc ('\t'); 112 i -= 8; 113 } 114 115 while (i > 0) { 116 outc (' '); 117 --i; 118 } 119 } 120 121 122 /** Make the table for possible eol matches. 123 * @return the newly allocated rule_can_match_eol table 124 */ 125 static struct yytbl_data *mkeoltbl (void) 126 { 127 int i; 128 flex_int8_t *tdata = 0; 129 struct yytbl_data *tbl; 130 131 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data)); 132 yytbl_data_init (tbl, YYTD_ID_RULE_CAN_MATCH_EOL); 133 tbl->td_flags = YYTD_DATA8; 134 tbl->td_lolen = num_rules + 1; 135 tbl->td_data = tdata = 136 (flex_int8_t *) calloc (tbl->td_lolen, sizeof (flex_int8_t)); 137 138 for (i = 1; i <= num_rules; i++) 139 tdata[i] = rule_has_nl[i] ? 1 : 0; 140 141 buf_prints (&yydmap_buf, 142 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n", 143 "flex_int32_t"); 144 return tbl; 145 } 146 147 /* Generate the table for possible eol matches. */ 148 static void geneoltbl (void) 149 { 150 int i; 151 152 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[["); 153 outn ("/* Table of booleans, true if rule could match eol. */"); 154 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol", 155 num_rules + 1); 156 157 if (gentables) { 158 for (i = 1; i <= num_rules; i++) { 159 out_dec ("%d, ", rule_has_nl[i] ? 1 : 0); 160 /* format nicely, 20 numbers per line. */ 161 if ((i % 20) == 19) 162 out ("\n "); 163 } 164 out (" };\n"); 165 } 166 outn ("]])"); 167 } 168 169 170 /* Generate the code to keep backing-up information. */ 171 172 void gen_backing_up (void) 173 { 174 if (reject || num_backing_up == 0) 175 return; 176 177 if (fullspd) 178 indent_puts ("if ( yy_current_state[-1].yy_nxt )"); 179 else 180 indent_puts ("if ( yy_accept[yy_current_state] )"); 181 182 indent_up (); 183 indent_puts ("{"); 184 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;"); 185 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;"); 186 indent_puts ("}"); 187 indent_down (); 188 } 189 190 191 /* Generate the code to perform the backing up. */ 192 193 void gen_bu_action (void) 194 { 195 if (reject || num_backing_up == 0) 196 return; 197 198 set_indent (3); 199 200 indent_puts ("case 0: /* must back up */"); 201 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */"); 202 indent_puts ("*yy_cp = YY_G(yy_hold_char);"); 203 204 if (fullspd || fulltbl) 205 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;"); 206 else 207 /* Backing-up info for compressed tables is taken \after/ 208 * yy_cp has been incremented for the next state. 209 */ 210 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);"); 211 212 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);"); 213 indent_puts ("goto yy_find_action;"); 214 outc ('\n'); 215 216 set_indent (0); 217 } 218 219 /** mkctbl - make full speed compressed transition table 220 * This is an array of structs; each struct a pair of integers. 221 * You should call mkssltbl() immediately after this. 222 * Then, I think, mkecstbl(). Arrrg. 223 * @return the newly allocated trans table 224 */ 225 226 static struct yytbl_data *mkctbl (void) 227 { 228 int i; 229 struct yytbl_data *tbl = 0; 230 flex_int32_t *tdata = 0, curr = 0; 231 int end_of_buffer_action = num_rules + 1; 232 233 buf_prints (&yydmap_buf, 234 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n", 235 ((tblend + numecs + 1) >= INT16_MAX 236 || long_align) ? "flex_int32_t" : "flex_int16_t"); 237 238 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data)); 239 yytbl_data_init (tbl, YYTD_ID_TRANSITION); 240 tbl->td_flags = YYTD_DATA32 | YYTD_STRUCT; 241 tbl->td_hilen = 0; 242 tbl->td_lolen = tblend + numecs + 1; /* number of structs */ 243 244 tbl->td_data = tdata = 245 (flex_int32_t *) calloc (tbl->td_lolen * 2, sizeof (flex_int32_t)); 246 247 /* We want the transition to be represented as the offset to the 248 * next state, not the actual state number, which is what it currently 249 * is. The offset is base[nxt[i]] - (base of current state)]. That's 250 * just the difference between the starting points of the two involved 251 * states (to - from). 252 * 253 * First, though, we need to find some way to put in our end-of-buffer 254 * flags and states. We do this by making a state with absolutely no 255 * transitions. We put it at the end of the table. 256 */ 257 258 /* We need to have room in nxt/chk for two more slots: One for the 259 * action and one for the end-of-buffer transition. We now *assume* 260 * that we're guaranteed the only character we'll try to index this 261 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure 262 * there's room for jam entries for other characters. 263 */ 264 265 while (tblend + 2 >= current_max_xpairs) 266 expand_nxt_chk (); 267 268 while (lastdfa + 1 >= current_max_dfas) 269 increase_max_dfas (); 270 271 base[lastdfa + 1] = tblend + 2; 272 nxt[tblend + 1] = end_of_buffer_action; 273 chk[tblend + 1] = numecs + 1; 274 chk[tblend + 2] = 1; /* anything but EOB */ 275 276 /* So that "make test" won't show arb. differences. */ 277 nxt[tblend + 2] = 0; 278 279 /* Make sure every state has an end-of-buffer transition and an 280 * action #. 281 */ 282 for (i = 0; i <= lastdfa; ++i) { 283 int anum = dfaacc[i].dfaacc_state; 284 int offset = base[i]; 285 286 chk[offset] = EOB_POSITION; 287 chk[offset - 1] = ACTION_POSITION; 288 nxt[offset - 1] = anum; /* action number */ 289 } 290 291 for (i = 0; i <= tblend; ++i) { 292 if (chk[i] == EOB_POSITION) { 293 tdata[curr++] = 0; 294 tdata[curr++] = base[lastdfa + 1] - i; 295 } 296 297 else if (chk[i] == ACTION_POSITION) { 298 tdata[curr++] = 0; 299 tdata[curr++] = nxt[i]; 300 } 301 302 else if (chk[i] > numecs || chk[i] == 0) { 303 tdata[curr++] = 0; 304 tdata[curr++] = 0; 305 } 306 else { /* verify, transition */ 307 308 tdata[curr++] = chk[i]; 309 tdata[curr++] = base[nxt[i]] - (i - chk[i]); 310 } 311 } 312 313 314 /* Here's the final, end-of-buffer state. */ 315 tdata[curr++] = chk[tblend + 1]; 316 tdata[curr++] = nxt[tblend + 1]; 317 318 tdata[curr++] = chk[tblend + 2]; 319 tdata[curr++] = nxt[tblend + 2]; 320 321 return tbl; 322 } 323 324 325 /** Make start_state_list table. 326 * @return the newly allocated start_state_list table 327 */ 328 static struct yytbl_data *mkssltbl (void) 329 { 330 struct yytbl_data *tbl = 0; 331 flex_int32_t *tdata = 0; 332 flex_int32_t i; 333 334 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data)); 335 yytbl_data_init (tbl, YYTD_ID_START_STATE_LIST); 336 tbl->td_flags = YYTD_DATA32 | YYTD_PTRANS; 337 tbl->td_hilen = 0; 338 tbl->td_lolen = lastsc * 2 + 1; 339 340 tbl->td_data = tdata = 341 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t)); 342 343 for (i = 0; i <= lastsc * 2; ++i) 344 tdata[i] = base[i]; 345 346 buf_prints (&yydmap_buf, 347 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n", 348 "struct yy_trans_info*"); 349 350 return tbl; 351 } 352 353 354 355 /* genctbl - generates full speed compressed transition table */ 356 357 void genctbl (void) 358 { 359 int i; 360 int end_of_buffer_action = num_rules + 1; 361 362 /* Table of verify for transition and offset to next state. */ 363 if (gentables) 364 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend + numecs + 1); 365 else 366 outn ("static yyconst struct yy_trans_info *yy_transition = 0;"); 367 368 /* We want the transition to be represented as the offset to the 369 * next state, not the actual state number, which is what it currently 370 * is. The offset is base[nxt[i]] - (base of current state)]. That's 371 * just the difference between the starting points of the two involved 372 * states (to - from). 373 * 374 * First, though, we need to find some way to put in our end-of-buffer 375 * flags and states. We do this by making a state with absolutely no 376 * transitions. We put it at the end of the table. 377 */ 378 379 /* We need to have room in nxt/chk for two more slots: One for the 380 * action and one for the end-of-buffer transition. We now *assume* 381 * that we're guaranteed the only character we'll try to index this 382 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure 383 * there's room for jam entries for other characters. 384 */ 385 386 while (tblend + 2 >= current_max_xpairs) 387 expand_nxt_chk (); 388 389 while (lastdfa + 1 >= current_max_dfas) 390 increase_max_dfas (); 391 392 base[lastdfa + 1] = tblend + 2; 393 nxt[tblend + 1] = end_of_buffer_action; 394 chk[tblend + 1] = numecs + 1; 395 chk[tblend + 2] = 1; /* anything but EOB */ 396 397 /* So that "make test" won't show arb. differences. */ 398 nxt[tblend + 2] = 0; 399 400 /* Make sure every state has an end-of-buffer transition and an 401 * action #. 402 */ 403 for (i = 0; i <= lastdfa; ++i) { 404 int anum = dfaacc[i].dfaacc_state; 405 int offset = base[i]; 406 407 chk[offset] = EOB_POSITION; 408 chk[offset - 1] = ACTION_POSITION; 409 nxt[offset - 1] = anum; /* action number */ 410 } 411 412 for (i = 0; i <= tblend; ++i) { 413 if (chk[i] == EOB_POSITION) 414 transition_struct_out (0, base[lastdfa + 1] - i); 415 416 else if (chk[i] == ACTION_POSITION) 417 transition_struct_out (0, nxt[i]); 418 419 else if (chk[i] > numecs || chk[i] == 0) 420 transition_struct_out (0, 0); /* unused slot */ 421 422 else /* verify, transition */ 423 transition_struct_out (chk[i], 424 base[nxt[i]] - (i - 425 chk[i])); 426 } 427 428 429 /* Here's the final, end-of-buffer state. */ 430 transition_struct_out (chk[tblend + 1], nxt[tblend + 1]); 431 transition_struct_out (chk[tblend + 2], nxt[tblend + 2]); 432 433 if (gentables) 434 outn (" };\n"); 435 436 /* Table of pointers to start states. */ 437 if (gentables) 438 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1); 439 else 440 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;"); 441 442 if (gentables) { 443 outn (" {"); 444 445 for (i = 0; i <= lastsc * 2; ++i) 446 out_dec (" &yy_transition[%d],\n", base[i]); 447 448 dataend (); 449 } 450 451 if (useecs) 452 genecs (); 453 } 454 455 456 /* mkecstbl - Make equivalence-class tables. */ 457 static struct yytbl_data *mkecstbl (void) 458 { 459 int i; 460 struct yytbl_data *tbl = 0; 461 flex_int32_t *tdata = 0; 462 463 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data)); 464 yytbl_data_init (tbl, YYTD_ID_EC); 465 tbl->td_flags |= YYTD_DATA32; 466 tbl->td_hilen = 0; 467 tbl->td_lolen = csize; 468 469 tbl->td_data = tdata = 470 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t)); 471 472 for (i = 1; i < csize; ++i) { 473 ecgroup[i] = ABS (ecgroup[i]); 474 tdata[i] = ecgroup[i]; 475 } 476 477 buf_prints (&yydmap_buf, 478 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n", 479 "YY_CHAR"); 480 481 return tbl; 482 } 483 484 /* Generate equivalence-class tables. */ 485 486 void genecs (void) 487 { 488 int i, j; 489 int numrows; 490 491 out_str_dec (get_yy_char_decl (), "yy_ec", csize); 492 493 for (i = 1; i < csize; ++i) { 494 ecgroup[i] = ABS (ecgroup[i]); 495 mkdata (ecgroup[i]); 496 } 497 498 dataend (); 499 500 if (trace) { 501 fputs (_("\n\nEquivalence Classes:\n\n"), stderr); 502 503 numrows = csize / 8; 504 505 for (j = 0; j < numrows; ++j) { 506 for (i = j; i < csize; i = i + numrows) { 507 fprintf (stderr, "%4s = %-2d", 508 readable_form (i), ecgroup[i]); 509 510 putc (' ', stderr); 511 } 512 513 putc ('\n', stderr); 514 } 515 } 516 } 517 518 519 /* Generate the code to find the action number. */ 520 521 void gen_find_action (void) 522 { 523 if (fullspd) 524 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;"); 525 526 else if (fulltbl) 527 indent_puts ("yy_act = yy_accept[yy_current_state];"); 528 529 else if (reject) { 530 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); 531 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); 532 533 if (!variable_trailing_context_rules) 534 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[["); 535 if(reject_really_used) 536 outn ("find_rule: /* we branch to this label when backing up */"); 537 if (!variable_trailing_context_rules) 538 outn ("]])\n"); 539 540 indent_puts 541 ("for ( ; ; ) /* until we find what rule we matched */"); 542 543 indent_up (); 544 545 indent_puts ("{"); 546 547 indent_puts 548 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )"); 549 indent_up (); 550 indent_puts ("{"); 551 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];"); 552 553 if (variable_trailing_context_rules) { 554 indent_puts 555 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||"); 556 indent_puts (" YY_G(yy_looking_for_trail_begin) )"); 557 indent_up (); 558 indent_puts ("{"); 559 560 indent_puts 561 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )"); 562 indent_up (); 563 indent_puts ("{"); 564 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;"); 565 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;"); 566 indent_puts ("break;"); 567 indent_puts ("}"); 568 indent_down (); 569 570 indent_puts ("}"); 571 indent_down (); 572 573 indent_puts 574 ("else if ( yy_act & YY_TRAILING_MASK )"); 575 indent_up (); 576 indent_puts ("{"); 577 indent_puts 578 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;"); 579 indent_puts 580 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;"); 581 582 if (real_reject) { 583 /* Remember matched text in case we back up 584 * due to REJECT. 585 */ 586 indent_puts 587 ("YY_G(yy_full_match) = yy_cp;"); 588 indent_puts 589 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);"); 590 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);"); 591 } 592 593 indent_puts ("}"); 594 indent_down (); 595 596 indent_puts ("else"); 597 indent_up (); 598 indent_puts ("{"); 599 indent_puts ("YY_G(yy_full_match) = yy_cp;"); 600 indent_puts 601 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);"); 602 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);"); 603 indent_puts ("break;"); 604 indent_puts ("}"); 605 indent_down (); 606 607 indent_puts ("++YY_G(yy_lp);"); 608 indent_puts ("goto find_rule;"); 609 } 610 611 else { 612 /* Remember matched text in case we back up due to 613 * trailing context plus REJECT. 614 */ 615 indent_up (); 616 indent_puts ("{"); 617 indent_puts ("YY_G(yy_full_match) = yy_cp;"); 618 indent_puts ("break;"); 619 indent_puts ("}"); 620 indent_down (); 621 } 622 623 indent_puts ("}"); 624 indent_down (); 625 626 indent_puts ("--yy_cp;"); 627 628 /* We could consolidate the following two lines with those at 629 * the beginning, but at the cost of complaints that we're 630 * branching inside a loop. 631 */ 632 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); 633 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); 634 635 indent_puts ("}"); 636 637 indent_down (); 638 } 639 640 else { /* compressed */ 641 indent_puts ("yy_act = yy_accept[yy_current_state];"); 642 643 if (interactive && !reject) { 644 /* Do the guaranteed-needed backing up to figure out 645 * the match. 646 */ 647 indent_puts ("if ( yy_act == 0 )"); 648 indent_up (); 649 indent_puts ("{ /* have to back up */"); 650 indent_puts 651 ("yy_cp = YY_G(yy_last_accepting_cpos);"); 652 indent_puts 653 ("yy_current_state = YY_G(yy_last_accepting_state);"); 654 indent_puts 655 ("yy_act = yy_accept[yy_current_state];"); 656 indent_puts ("}"); 657 indent_down (); 658 } 659 } 660 } 661 662 /* mkftbl - make the full table and return the struct . 663 * you should call mkecstbl() after this. 664 */ 665 666 struct yytbl_data *mkftbl (void) 667 { 668 int i; 669 int end_of_buffer_action = num_rules + 1; 670 struct yytbl_data *tbl; 671 flex_int32_t *tdata = 0; 672 673 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data)); 674 yytbl_data_init (tbl, YYTD_ID_ACCEPT); 675 tbl->td_flags |= YYTD_DATA32; 676 tbl->td_hilen = 0; /* it's a one-dimensional array */ 677 tbl->td_lolen = lastdfa + 1; 678 679 tbl->td_data = tdata = 680 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t)); 681 682 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; 683 684 for (i = 1; i <= lastdfa; ++i) { 685 int anum = dfaacc[i].dfaacc_state; 686 687 tdata[i] = anum; 688 689 if (trace && anum) 690 fprintf (stderr, _("state # %d accepts: [%d]\n"), 691 i, anum); 692 } 693 694 buf_prints (&yydmap_buf, 695 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n", 696 long_align ? "flex_int32_t" : "flex_int16_t"); 697 return tbl; 698 } 699 700 701 /* genftbl - generate full transition table */ 702 703 void genftbl (void) 704 { 705 int i; 706 int end_of_buffer_action = num_rules + 1; 707 708 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (), 709 "yy_accept", lastdfa + 1); 710 711 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; 712 713 for (i = 1; i <= lastdfa; ++i) { 714 int anum = dfaacc[i].dfaacc_state; 715 716 mkdata (anum); 717 718 if (trace && anum) 719 fprintf (stderr, _("state # %d accepts: [%d]\n"), 720 i, anum); 721 } 722 723 dataend (); 724 725 if (useecs) 726 genecs (); 727 728 /* Don't have to dump the actual full table entries - they were 729 * created on-the-fly. 730 */ 731 } 732 733 734 /* Generate the code to find the next compressed-table state. */ 735 736 void gen_next_compressed_state (char_map) 737 char *char_map; 738 { 739 indent_put2s ("YY_CHAR yy_c = %s;", char_map); 740 741 /* Save the backing-up info \before/ computing the next state 742 * because we always compute one more state than needed - we 743 * always proceed until we reach a jam state 744 */ 745 gen_backing_up (); 746 747 indent_puts 748 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )"); 749 indent_up (); 750 indent_puts ("{"); 751 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];"); 752 753 if (usemecs) { 754 /* We've arrange it so that templates are never chained 755 * to one another. This means we can afford to make a 756 * very simple test to see if we need to convert to 757 * yy_c's meta-equivalence class without worrying 758 * about erroneously looking up the meta-equivalence 759 * class twice 760 */ 761 do_indent (); 762 763 /* lastdfa + 2 is the beginning of the templates */ 764 out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2); 765 766 indent_up (); 767 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];"); 768 indent_down (); 769 } 770 771 indent_puts ("}"); 772 indent_down (); 773 774 indent_puts 775 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];"); 776 } 777 778 779 /* Generate the code to find the next match. */ 780 781 void gen_next_match (void) 782 { 783 /* NOTE - changes in here should be reflected in gen_next_state() and 784 * gen_NUL_trans(). 785 */ 786 char *char_map = useecs ? 787 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)"; 788 789 char *char_map_2 = useecs ? 790 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)"; 791 792 if (fulltbl) { 793 if (gentables) 794 indent_put2s 795 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )", 796 char_map); 797 else 798 indent_put2s 799 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )", 800 char_map); 801 802 indent_up (); 803 804 if (num_backing_up > 0) { 805 indent_puts ("{"); 806 gen_backing_up (); 807 outc ('\n'); 808 } 809 810 indent_puts ("++yy_cp;"); 811 812 if (num_backing_up > 0) 813 814 indent_puts ("}"); 815 816 indent_down (); 817 818 outc ('\n'); 819 indent_puts ("yy_current_state = -yy_current_state;"); 820 } 821 822 else if (fullspd) { 823 indent_puts ("{"); 824 indent_puts 825 ("yyconst struct yy_trans_info *yy_trans_info;\n"); 826 indent_puts ("YY_CHAR yy_c;\n"); 827 indent_put2s ("for ( yy_c = %s;", char_map); 828 indent_puts 829 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->"); 830 indent_puts ("yy_verify == yy_c;"); 831 indent_put2s (" yy_c = %s )", char_map_2); 832 833 indent_up (); 834 835 if (num_backing_up > 0) 836 indent_puts ("{"); 837 838 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); 839 840 if (num_backing_up > 0) { 841 outc ('\n'); 842 gen_backing_up (); 843 indent_puts ("}"); 844 } 845 846 indent_down (); 847 indent_puts ("}"); 848 } 849 850 else { /* compressed */ 851 indent_puts ("do"); 852 853 indent_up (); 854 indent_puts ("{"); 855 856 gen_next_state (false); 857 858 indent_puts ("++yy_cp;"); 859 860 861 indent_puts ("}"); 862 indent_down (); 863 864 do_indent (); 865 866 if (interactive) 867 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase); 868 else 869 out_dec ("while ( yy_current_state != %d );\n", 870 jamstate); 871 872 if (!reject && !interactive) { 873 /* Do the guaranteed-needed backing up to figure out 874 * the match. 875 */ 876 indent_puts 877 ("yy_cp = YY_G(yy_last_accepting_cpos);"); 878 indent_puts 879 ("yy_current_state = YY_G(yy_last_accepting_state);"); 880 } 881 } 882 } 883 884 885 /* Generate the code to find the next state. */ 886 887 void gen_next_state (worry_about_NULs) 888 int worry_about_NULs; 889 { /* NOTE - changes in here should be reflected in gen_next_match() */ 890 char char_map[256]; 891 892 if (worry_about_NULs && !nultrans) { 893 if (useecs) 894 snprintf (char_map, sizeof(char_map), 895 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)", 896 NUL_ec); 897 else 898 snprintf (char_map, sizeof(char_map), 899 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", 900 NUL_ec); 901 } 902 903 else 904 strcpy (char_map, useecs ? 905 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : 906 "YY_SC_TO_UI(*yy_cp)"); 907 908 if (worry_about_NULs && nultrans) { 909 if (!fulltbl && !fullspd) 910 /* Compressed tables back up *before* they match. */ 911 gen_backing_up (); 912 913 indent_puts ("if ( *yy_cp )"); 914 indent_up (); 915 indent_puts ("{"); 916 } 917 918 if (fulltbl) { 919 if (gentables) 920 indent_put2s 921 ("yy_current_state = yy_nxt[yy_current_state][%s];", 922 char_map); 923 else 924 indent_put2s 925 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];", 926 char_map); 927 } 928 929 else if (fullspd) 930 indent_put2s 931 ("yy_current_state += yy_current_state[%s].yy_nxt;", 932 char_map); 933 934 else 935 gen_next_compressed_state (char_map); 936 937 if (worry_about_NULs && nultrans) { 938 939 indent_puts ("}"); 940 indent_down (); 941 indent_puts ("else"); 942 indent_up (); 943 indent_puts 944 ("yy_current_state = yy_NUL_trans[yy_current_state];"); 945 indent_down (); 946 } 947 948 if (fullspd || fulltbl) 949 gen_backing_up (); 950 951 if (reject) 952 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;"); 953 } 954 955 956 /* Generate the code to make a NUL transition. */ 957 958 void gen_NUL_trans (void) 959 { /* NOTE - changes in here should be reflected in gen_next_match() */ 960 /* Only generate a definition for "yy_cp" if we'll generate code 961 * that uses it. Otherwise lint and the like complain. 962 */ 963 int need_backing_up = (num_backing_up > 0 && !reject); 964 965 if (need_backing_up && (!nultrans || fullspd || fulltbl)) 966 /* We're going to need yy_cp lying around for the call 967 * below to gen_backing_up(). 968 */ 969 indent_puts ("char *yy_cp = YY_G(yy_c_buf_p);"); 970 971 outc ('\n'); 972 973 if (nultrans) { 974 indent_puts 975 ("yy_current_state = yy_NUL_trans[yy_current_state];"); 976 indent_puts ("yy_is_jam = (yy_current_state == 0);"); 977 } 978 979 else if (fulltbl) { 980 do_indent (); 981 if (gentables) 982 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec); 983 else 984 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec); 985 indent_puts ("yy_is_jam = (yy_current_state <= 0);"); 986 } 987 988 else if (fullspd) { 989 do_indent (); 990 out_dec ("int yy_c = %d;\n", NUL_ec); 991 992 indent_puts 993 ("yyconst struct yy_trans_info *yy_trans_info;\n"); 994 indent_puts 995 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];"); 996 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); 997 998 indent_puts 999 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);"); 1000 } 1001 1002 else { 1003 char NUL_ec_str[20]; 1004 1005 snprintf (NUL_ec_str, sizeof(NUL_ec_str), "%d", NUL_ec); 1006 gen_next_compressed_state (NUL_ec_str); 1007 1008 do_indent (); 1009 out_dec ("yy_is_jam = (yy_current_state == %d);\n", 1010 jamstate); 1011 1012 if (reject) { 1013 /* Only stack this state if it's a transition we 1014 * actually make. If we stack it on a jam, then 1015 * the state stack and yy_c_buf_p get out of sync. 1016 */ 1017 indent_puts ("if ( ! yy_is_jam )"); 1018 indent_up (); 1019 indent_puts 1020 ("*YY_G(yy_state_ptr)++ = yy_current_state;"); 1021 indent_down (); 1022 } 1023 } 1024 1025 /* If we've entered an accepting state, back up; note that 1026 * compressed tables have *already* done such backing up, so 1027 * we needn't bother with it again. 1028 */ 1029 if (need_backing_up && (fullspd || fulltbl)) { 1030 outc ('\n'); 1031 indent_puts ("if ( ! yy_is_jam )"); 1032 indent_up (); 1033 indent_puts ("{"); 1034 gen_backing_up (); 1035 indent_puts ("}"); 1036 indent_down (); 1037 } 1038 } 1039 1040 1041 /* Generate the code to find the start state. */ 1042 1043 void gen_start_state (void) 1044 { 1045 if (fullspd) { 1046 if (bol_needed) { 1047 indent_puts 1048 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];"); 1049 } 1050 else 1051 indent_puts 1052 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];"); 1053 } 1054 1055 else { 1056 indent_puts ("yy_current_state = YY_G(yy_start);"); 1057 1058 if (bol_needed) 1059 indent_puts ("yy_current_state += YY_AT_BOL();"); 1060 1061 if (reject) { 1062 /* Set up for storing up states. */ 1063 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[["); 1064 indent_puts 1065 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);"); 1066 indent_puts 1067 ("*YY_G(yy_state_ptr)++ = yy_current_state;"); 1068 outn ("]])"); 1069 } 1070 } 1071 } 1072 1073 1074 /* gentabs - generate data statements for the transition tables */ 1075 1076 void gentabs (void) 1077 { 1078 int i, j, k, *accset, nacc, *acc_array, total_states; 1079 int end_of_buffer_action = num_rules + 1; 1080 struct yytbl_data *yyacc_tbl = 0, *yymeta_tbl = 0, *yybase_tbl = 0, 1081 *yydef_tbl = 0, *yynxt_tbl = 0, *yychk_tbl = 0, *yyacclist_tbl=0; 1082 flex_int32_t *yyacc_data = 0, *yybase_data = 0, *yydef_data = 0, 1083 *yynxt_data = 0, *yychk_data = 0, *yyacclist_data=0; 1084 flex_int32_t yybase_curr = 0, yyacclist_curr=0,yyacc_curr=0; 1085 1086 acc_array = allocate_integer_array (current_max_dfas); 1087 nummt = 0; 1088 1089 /* The compressed table format jams by entering the "jam state", 1090 * losing information about the previous state in the process. 1091 * In order to recover the previous state, we effectively need 1092 * to keep backing-up information. 1093 */ 1094 ++num_backing_up; 1095 1096 if (reject) { 1097 /* Write out accepting list and pointer list. 1098 1099 * First we generate the "yy_acclist" array. In the process, 1100 * we compute the indices that will go into the "yy_accept" 1101 * array, and save the indices in the dfaacc array. 1102 */ 1103 int EOB_accepting_list[2]; 1104 1105 /* Set up accepting structures for the End Of Buffer state. */ 1106 EOB_accepting_list[0] = 0; 1107 EOB_accepting_list[1] = end_of_buffer_action; 1108 accsiz[end_of_buffer_state] = 1; 1109 dfaacc[end_of_buffer_state].dfaacc_set = 1110 EOB_accepting_list; 1111 1112 out_str_dec (long_align ? get_int32_decl () : 1113 get_int16_decl (), "yy_acclist", MAX (numas, 1114 1) + 1); 1115 1116 buf_prints (&yydmap_buf, 1117 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n", 1118 long_align ? "flex_int32_t" : "flex_int16_t"); 1119 1120 yyacclist_tbl = (struct yytbl_data*)calloc(1,sizeof(struct yytbl_data)); 1121 yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST); 1122 yyacclist_tbl->td_lolen = MAX(numas,1) + 1; 1123 yyacclist_tbl->td_data = yyacclist_data = 1124 (flex_int32_t *) calloc (yyacclist_tbl->td_lolen, sizeof (flex_int32_t)); 1125 yyacclist_curr = 1; 1126 1127 j = 1; /* index into "yy_acclist" array */ 1128 1129 for (i = 1; i <= lastdfa; ++i) { 1130 acc_array[i] = j; 1131 1132 if (accsiz[i] != 0) { 1133 accset = dfaacc[i].dfaacc_set; 1134 nacc = accsiz[i]; 1135 1136 if (trace) 1137 fprintf (stderr, 1138 _("state # %d accepts: "), 1139 i); 1140 1141 for (k = 1; k <= nacc; ++k) { 1142 int accnum = accset[k]; 1143 1144 ++j; 1145 1146 if (variable_trailing_context_rules 1147 && !(accnum & 1148 YY_TRAILING_HEAD_MASK) 1149 && accnum > 0 1150 && accnum <= num_rules 1151 && rule_type[accnum] == 1152 RULE_VARIABLE) { 1153 /* Special hack to flag 1154 * accepting number as part 1155 * of trailing context rule. 1156 */ 1157 accnum |= YY_TRAILING_MASK; 1158 } 1159 1160 mkdata (accnum); 1161 yyacclist_data[yyacclist_curr++] = accnum; 1162 1163 if (trace) { 1164 fprintf (stderr, "[%d]", 1165 accset[k]); 1166 1167 if (k < nacc) 1168 fputs (", ", 1169 stderr); 1170 else 1171 putc ('\n', 1172 stderr); 1173 } 1174 } 1175 } 1176 } 1177 1178 /* add accepting number for the "jam" state */ 1179 acc_array[i] = j; 1180 1181 dataend (); 1182 if (tablesext) { 1183 yytbl_data_compress (yyacclist_tbl); 1184 if (yytbl_data_fwrite (&tableswr, yyacclist_tbl) < 0) 1185 flexerror (_("Could not write yyacclist_tbl")); 1186 yytbl_data_destroy (yyacclist_tbl); 1187 yyacclist_tbl = NULL; 1188 } 1189 } 1190 1191 else { 1192 dfaacc[end_of_buffer_state].dfaacc_state = 1193 end_of_buffer_action; 1194 1195 for (i = 1; i <= lastdfa; ++i) 1196 acc_array[i] = dfaacc[i].dfaacc_state; 1197 1198 /* add accepting number for jam state */ 1199 acc_array[i] = 0; 1200 } 1201 1202 /* Begin generating yy_accept */ 1203 1204 /* Spit out "yy_accept" array. If we're doing "reject", it'll be 1205 * pointers into the "yy_acclist" array. Otherwise it's actual 1206 * accepting numbers. In either case, we just dump the numbers. 1207 */ 1208 1209 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays 1210 * beginning at 0 and for "jam" state. 1211 */ 1212 k = lastdfa + 2; 1213 1214 if (reject) 1215 /* We put a "cap" on the table associating lists of accepting 1216 * numbers with state numbers. This is needed because we tell 1217 * where the end of an accepting list is by looking at where 1218 * the list for the next state starts. 1219 */ 1220 ++k; 1221 1222 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (), 1223 "yy_accept", k); 1224 1225 buf_prints (&yydmap_buf, 1226 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n", 1227 long_align ? "flex_int32_t" : "flex_int16_t"); 1228 1229 yyacc_tbl = 1230 (struct yytbl_data *) calloc (1, 1231 sizeof (struct yytbl_data)); 1232 yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT); 1233 yyacc_tbl->td_lolen = k; 1234 yyacc_tbl->td_data = yyacc_data = 1235 (flex_int32_t *) calloc (yyacc_tbl->td_lolen, sizeof (flex_int32_t)); 1236 yyacc_curr=1; 1237 1238 for (i = 1; i <= lastdfa; ++i) { 1239 mkdata (acc_array[i]); 1240 yyacc_data[yyacc_curr++] = acc_array[i]; 1241 1242 if (!reject && trace && acc_array[i]) 1243 fprintf (stderr, _("state # %d accepts: [%d]\n"), 1244 i, acc_array[i]); 1245 } 1246 1247 /* Add entry for "jam" state. */ 1248 mkdata (acc_array[i]); 1249 yyacc_data[yyacc_curr++] = acc_array[i]; 1250 1251 if (reject) { 1252 /* Add "cap" for the list. */ 1253 mkdata (acc_array[i]); 1254 yyacc_data[yyacc_curr++] = acc_array[i]; 1255 } 1256 1257 dataend (); 1258 if (tablesext) { 1259 yytbl_data_compress (yyacc_tbl); 1260 if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0) 1261 flexerror (_("Could not write yyacc_tbl")); 1262 yytbl_data_destroy (yyacc_tbl); 1263 yyacc_tbl = NULL; 1264 } 1265 /* End generating yy_accept */ 1266 1267 if (useecs) { 1268 1269 genecs (); 1270 if (tablesext) { 1271 struct yytbl_data *tbl; 1272 1273 tbl = mkecstbl (); 1274 yytbl_data_compress (tbl); 1275 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1276 flexerror (_("Could not write ecstbl")); 1277 yytbl_data_destroy (tbl); 1278 tbl = 0; 1279 } 1280 } 1281 1282 if (usemecs) { 1283 /* Begin generating yy_meta */ 1284 /* Write out meta-equivalence classes (used to index 1285 * templates with). 1286 */ 1287 flex_int32_t *yymecs_data = 0; 1288 yymeta_tbl = 1289 (struct yytbl_data *) calloc (1, 1290 sizeof (struct 1291 yytbl_data)); 1292 yytbl_data_init (yymeta_tbl, YYTD_ID_META); 1293 yymeta_tbl->td_lolen = numecs + 1; 1294 yymeta_tbl->td_data = yymecs_data = 1295 (flex_int32_t *) calloc (yymeta_tbl->td_lolen, 1296 sizeof (flex_int32_t)); 1297 1298 if (trace) 1299 fputs (_("\n\nMeta-Equivalence Classes:\n"), 1300 stderr); 1301 1302 out_str_dec (get_yy_char_decl (), "yy_meta", numecs + 1); 1303 buf_prints (&yydmap_buf, 1304 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n", 1305 "YY_CHAR"); 1306 1307 for (i = 1; i <= numecs; ++i) { 1308 if (trace) 1309 fprintf (stderr, "%d = %d\n", 1310 i, ABS (tecbck[i])); 1311 1312 mkdata (ABS (tecbck[i])); 1313 yymecs_data[i] = ABS (tecbck[i]); 1314 } 1315 1316 dataend (); 1317 if (tablesext) { 1318 yytbl_data_compress (yymeta_tbl); 1319 if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0) 1320 flexerror (_ 1321 ("Could not write yymeta_tbl")); 1322 yytbl_data_destroy (yymeta_tbl); 1323 yymeta_tbl = NULL; 1324 } 1325 /* End generating yy_meta */ 1326 } 1327 1328 total_states = lastdfa + numtemps; 1329 1330 /* Begin generating yy_base */ 1331 out_str_dec ((tblend >= INT16_MAX || long_align) ? 1332 get_uint32_decl () : get_uint16_decl (), 1333 "yy_base", total_states + 1); 1334 1335 buf_prints (&yydmap_buf, 1336 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n", 1337 (tblend >= INT16_MAX 1338 || long_align) ? "flex_uint32_t" : "flex_uint16_t"); 1339 yybase_tbl = 1340 (struct yytbl_data *) calloc (1, 1341 sizeof (struct yytbl_data)); 1342 yytbl_data_init (yybase_tbl, YYTD_ID_BASE); 1343 yybase_tbl->td_lolen = total_states + 1; 1344 yybase_tbl->td_data = yybase_data = 1345 (flex_int32_t *) calloc (yybase_tbl->td_lolen, 1346 sizeof (flex_int32_t)); 1347 yybase_curr = 1; 1348 1349 for (i = 1; i <= lastdfa; ++i) { 1350 int d = def[i]; 1351 1352 if (base[i] == JAMSTATE) 1353 base[i] = jambase; 1354 1355 if (d == JAMSTATE) 1356 def[i] = jamstate; 1357 1358 else if (d < 0) { 1359 /* Template reference. */ 1360 ++tmpuses; 1361 def[i] = lastdfa - d + 1; 1362 } 1363 1364 mkdata (base[i]); 1365 yybase_data[yybase_curr++] = base[i]; 1366 } 1367 1368 /* Generate jam state's base index. */ 1369 mkdata (base[i]); 1370 yybase_data[yybase_curr++] = base[i]; 1371 1372 for (++i /* skip jam state */ ; i <= total_states; ++i) { 1373 mkdata (base[i]); 1374 yybase_data[yybase_curr++] = base[i]; 1375 def[i] = jamstate; 1376 } 1377 1378 dataend (); 1379 if (tablesext) { 1380 yytbl_data_compress (yybase_tbl); 1381 if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0) 1382 flexerror (_("Could not write yybase_tbl")); 1383 yytbl_data_destroy (yybase_tbl); 1384 yybase_tbl = NULL; 1385 } 1386 /* End generating yy_base */ 1387 1388 1389 /* Begin generating yy_def */ 1390 out_str_dec ((total_states >= INT16_MAX || long_align) ? 1391 get_int32_decl () : get_int16_decl (), 1392 "yy_def", total_states + 1); 1393 1394 buf_prints (&yydmap_buf, 1395 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n", 1396 (total_states >= INT16_MAX 1397 || long_align) ? "flex_int32_t" : "flex_int16_t"); 1398 1399 yydef_tbl = 1400 (struct yytbl_data *) calloc (1, 1401 sizeof (struct yytbl_data)); 1402 yytbl_data_init (yydef_tbl, YYTD_ID_DEF); 1403 yydef_tbl->td_lolen = total_states + 1; 1404 yydef_tbl->td_data = yydef_data = 1405 (flex_int32_t *) calloc (yydef_tbl->td_lolen, sizeof (flex_int32_t)); 1406 1407 for (i = 1; i <= total_states; ++i) { 1408 mkdata (def[i]); 1409 yydef_data[i] = def[i]; 1410 } 1411 1412 dataend (); 1413 if (tablesext) { 1414 yytbl_data_compress (yydef_tbl); 1415 if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0) 1416 flexerror (_("Could not write yydef_tbl")); 1417 yytbl_data_destroy (yydef_tbl); 1418 yydef_tbl = NULL; 1419 } 1420 /* End generating yy_def */ 1421 1422 1423 /* Begin generating yy_nxt */ 1424 out_str_dec ((total_states >= INT16_MAX || long_align) ? 1425 get_uint32_decl () : get_uint16_decl (), "yy_nxt", 1426 tblend + 1); 1427 1428 buf_prints (&yydmap_buf, 1429 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n", 1430 (total_states >= INT16_MAX 1431 || long_align) ? "flex_uint32_t" : "flex_uint16_t"); 1432 1433 yynxt_tbl = 1434 (struct yytbl_data *) calloc (1, 1435 sizeof (struct yytbl_data)); 1436 yytbl_data_init (yynxt_tbl, YYTD_ID_NXT); 1437 yynxt_tbl->td_lolen = tblend + 1; 1438 yynxt_tbl->td_data = yynxt_data = 1439 (flex_int32_t *) calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t)); 1440 1441 for (i = 1; i <= tblend; ++i) { 1442 /* Note, the order of the following test is important. 1443 * If chk[i] is 0, then nxt[i] is undefined. 1444 */ 1445 if (chk[i] == 0 || nxt[i] == 0) 1446 nxt[i] = jamstate; /* new state is the JAM state */ 1447 1448 mkdata (nxt[i]); 1449 yynxt_data[i] = nxt[i]; 1450 } 1451 1452 dataend (); 1453 if (tablesext) { 1454 yytbl_data_compress (yynxt_tbl); 1455 if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0) 1456 flexerror (_("Could not write yynxt_tbl")); 1457 yytbl_data_destroy (yynxt_tbl); 1458 yynxt_tbl = NULL; 1459 } 1460 /* End generating yy_nxt */ 1461 1462 /* Begin generating yy_chk */ 1463 out_str_dec ((total_states >= INT16_MAX || long_align) ? 1464 get_int32_decl () : get_int16_decl (), "yy_chk", 1465 tblend + 1); 1466 1467 buf_prints (&yydmap_buf, 1468 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n", 1469 (total_states >= INT16_MAX 1470 || long_align) ? "flex_int32_t" : "flex_int16_t"); 1471 1472 yychk_tbl = 1473 (struct yytbl_data *) calloc (1, 1474 sizeof (struct yytbl_data)); 1475 yytbl_data_init (yychk_tbl, YYTD_ID_CHK); 1476 yychk_tbl->td_lolen = tblend + 1; 1477 yychk_tbl->td_data = yychk_data = 1478 (flex_int32_t *) calloc (yychk_tbl->td_lolen, sizeof (flex_int32_t)); 1479 1480 for (i = 1; i <= tblend; ++i) { 1481 if (chk[i] == 0) 1482 ++nummt; 1483 1484 mkdata (chk[i]); 1485 yychk_data[i] = chk[i]; 1486 } 1487 1488 dataend (); 1489 if (tablesext) { 1490 yytbl_data_compress (yychk_tbl); 1491 if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0) 1492 flexerror (_("Could not write yychk_tbl")); 1493 yytbl_data_destroy (yychk_tbl); 1494 yychk_tbl = NULL; 1495 } 1496 /* End generating yy_chk */ 1497 1498 flex_free ((void *) acc_array); 1499 } 1500 1501 1502 /* Write out a formatted string (with a secondary string argument) at the 1503 * current indentation level, adding a final newline. 1504 */ 1505 1506 void indent_put2s (fmt, arg) 1507 const char *fmt, *arg; 1508 { 1509 do_indent (); 1510 out_str (fmt, arg); 1511 outn (""); 1512 } 1513 1514 1515 /* Write out a string at the current indentation level, adding a final 1516 * newline. 1517 */ 1518 1519 void indent_puts (str) 1520 const char *str; 1521 { 1522 do_indent (); 1523 outn (str); 1524 } 1525 1526 1527 /* make_tables - generate transition tables and finishes generating output file 1528 */ 1529 1530 void make_tables (void) 1531 { 1532 int i; 1533 int did_eof_rule = false; 1534 struct yytbl_data *yynultrans_tbl = NULL; 1535 1536 1537 skelout (); /* %% [2.0] - break point in skel */ 1538 1539 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore 1540 * being used. 1541 */ 1542 set_indent (1); 1543 1544 if (yymore_used && !yytext_is_array) { 1545 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\"); 1546 indent_puts 1547 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\"); 1548 } 1549 1550 else 1551 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\"); 1552 1553 /* Now also deal with copying yytext_ptr to yytext if needed. */ 1554 skelout (); /* %% [3.0] - break point in skel */ 1555 if (yytext_is_array) { 1556 if (yymore_used) 1557 indent_puts 1558 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\"); 1559 else 1560 indent_puts ("if ( yyleng >= YYLMAX ) \\"); 1561 1562 indent_up (); 1563 indent_puts 1564 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\"); 1565 indent_down (); 1566 1567 if (yymore_used) { 1568 indent_puts 1569 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\"); 1570 indent_puts ("yyleng += YY_G(yy_more_offset); \\"); 1571 indent_puts 1572 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\"); 1573 indent_puts ("YY_G(yy_more_offset) = 0; \\"); 1574 } 1575 else { 1576 indent_puts 1577 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\"); 1578 } 1579 } 1580 1581 set_indent (0); 1582 1583 skelout (); /* %% [4.0] - break point in skel */ 1584 1585 1586 /* This is where we REALLY begin generating the tables. */ 1587 1588 out_dec ("#define YY_NUM_RULES %d\n", num_rules); 1589 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1); 1590 1591 if (fullspd) { 1592 /* Need to define the transet type as a size large 1593 * enough to hold the biggest offset. 1594 */ 1595 int total_table_size = tblend + numecs + 1; 1596 char *trans_offset_type = 1597 (total_table_size >= INT16_MAX || long_align) ? 1598 "flex_int32_t" : "flex_int16_t"; 1599 1600 set_indent (0); 1601 indent_puts ("struct yy_trans_info"); 1602 indent_up (); 1603 indent_puts ("{"); 1604 1605 /* We require that yy_verify and yy_nxt must be of the same size int. */ 1606 indent_put2s ("%s yy_verify;", trans_offset_type); 1607 1608 /* In cases where its sister yy_verify *is* a "yes, there is 1609 * a transition", yy_nxt is the offset (in records) to the 1610 * next state. In most cases where there is no transition, 1611 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th 1612 * record of a state, though, then yy_nxt is the action number 1613 * for that state. 1614 */ 1615 1616 indent_put2s ("%s yy_nxt;", trans_offset_type); 1617 indent_puts ("};"); 1618 indent_down (); 1619 } 1620 else { 1621 /* We generate a bogus 'struct yy_trans_info' data type 1622 * so we can guarantee that it is always declared in the skel. 1623 * This is so we can compile "sizeof(struct yy_trans_info)" 1624 * in any scanner. 1625 */ 1626 indent_puts 1627 ("/* This struct is not used in this scanner,"); 1628 indent_puts (" but its presence is necessary. */"); 1629 indent_puts ("struct yy_trans_info"); 1630 indent_up (); 1631 indent_puts ("{"); 1632 indent_puts ("flex_int32_t yy_verify;"); 1633 indent_puts ("flex_int32_t yy_nxt;"); 1634 indent_puts ("};"); 1635 indent_down (); 1636 } 1637 1638 if (fullspd) { 1639 genctbl (); 1640 if (tablesext) { 1641 struct yytbl_data *tbl; 1642 1643 tbl = mkctbl (); 1644 yytbl_data_compress (tbl); 1645 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1646 flexerror (_("Could not write ftbl")); 1647 yytbl_data_destroy (tbl); 1648 1649 tbl = mkssltbl (); 1650 yytbl_data_compress (tbl); 1651 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1652 flexerror (_("Could not write ssltbl")); 1653 yytbl_data_destroy (tbl); 1654 tbl = 0; 1655 1656 if (useecs) { 1657 tbl = mkecstbl (); 1658 yytbl_data_compress (tbl); 1659 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1660 flexerror (_ 1661 ("Could not write ecstbl")); 1662 yytbl_data_destroy (tbl); 1663 tbl = 0; 1664 } 1665 } 1666 } 1667 else if (fulltbl) { 1668 genftbl (); 1669 if (tablesext) { 1670 struct yytbl_data *tbl; 1671 1672 tbl = mkftbl (); 1673 yytbl_data_compress (tbl); 1674 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1675 flexerror (_("Could not write ftbl")); 1676 yytbl_data_destroy (tbl); 1677 tbl = 0; 1678 1679 if (useecs) { 1680 tbl = mkecstbl (); 1681 yytbl_data_compress (tbl); 1682 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1683 flexerror (_ 1684 ("Could not write ecstbl")); 1685 yytbl_data_destroy (tbl); 1686 tbl = 0; 1687 } 1688 } 1689 } 1690 else 1691 gentabs (); 1692 1693 if (do_yylineno) { 1694 1695 geneoltbl (); 1696 1697 if (tablesext) { 1698 struct yytbl_data *tbl; 1699 1700 tbl = mkeoltbl (); 1701 yytbl_data_compress (tbl); 1702 if (yytbl_data_fwrite (&tableswr, tbl) < 0) 1703 flexerror (_("Could not write eoltbl")); 1704 yytbl_data_destroy (tbl); 1705 tbl = 0; 1706 } 1707 } 1708 1709 /* Definitions for backing up. We don't need them if REJECT 1710 * is being used because then we use an alternative backin-up 1711 * technique instead. 1712 */ 1713 if (num_backing_up > 0 && !reject) { 1714 if (!C_plus_plus && !reentrant) { 1715 indent_puts 1716 ("static yy_state_type yy_last_accepting_state;"); 1717 indent_puts 1718 ("static char *yy_last_accepting_cpos;\n"); 1719 } 1720 } 1721 1722 if (nultrans) { 1723 flex_int32_t *yynultrans_data = 0; 1724 1725 /* Begin generating yy_NUL_trans */ 1726 out_str_dec (get_state_decl (), "yy_NUL_trans", 1727 lastdfa + 1); 1728 buf_prints (&yydmap_buf, 1729 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n", 1730 (fullspd) ? "struct yy_trans_info*" : 1731 "flex_int32_t"); 1732 1733 yynultrans_tbl = 1734 (struct yytbl_data *) calloc (1, 1735 sizeof (struct 1736 yytbl_data)); 1737 yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS); 1738 if (fullspd) 1739 yynultrans_tbl->td_flags |= YYTD_PTRANS; 1740 yynultrans_tbl->td_lolen = lastdfa + 1; 1741 yynultrans_tbl->td_data = yynultrans_data = 1742 (flex_int32_t *) calloc (yynultrans_tbl->td_lolen, 1743 sizeof (flex_int32_t)); 1744 1745 for (i = 1; i <= lastdfa; ++i) { 1746 if (fullspd) { 1747 out_dec (" &yy_transition[%d],\n", 1748 base[i]); 1749 yynultrans_data[i] = base[i]; 1750 } 1751 else { 1752 mkdata (nultrans[i]); 1753 yynultrans_data[i] = nultrans[i]; 1754 } 1755 } 1756 1757 dataend (); 1758 if (tablesext) { 1759 yytbl_data_compress (yynultrans_tbl); 1760 if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) < 1761 0) 1762 flexerror (_ 1763 ("Could not write yynultrans_tbl")); 1764 } 1765 1766 if (yynultrans_tbl != NULL) { 1767 yytbl_data_destroy (yynultrans_tbl); 1768 yynultrans_tbl = NULL; 1769 } 1770 1771 /* End generating yy_NUL_trans */ 1772 } 1773 1774 if (!C_plus_plus && !reentrant) { 1775 indent_puts ("extern int yy_flex_debug;"); 1776 indent_put2s ("int yy_flex_debug = %s;\n", 1777 ddebug ? "1" : "0"); 1778 } 1779 1780 if (ddebug) { /* Spit out table mapping rules to line numbers. */ 1781 out_str_dec (long_align ? get_int32_decl () : 1782 get_int16_decl (), "yy_rule_linenum", 1783 num_rules); 1784 for (i = 1; i < num_rules; ++i) 1785 mkdata (rule_linenum[i]); 1786 dataend (); 1787 } 1788 1789 if (reject) { 1790 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[["); 1791 /* Declare state buffer variables. */ 1792 if (!C_plus_plus && !reentrant) { 1793 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;"); 1794 outn ("static char *yy_full_match;"); 1795 outn ("static int yy_lp;"); 1796 } 1797 1798 if (variable_trailing_context_rules) { 1799 if (!C_plus_plus && !reentrant) { 1800 outn ("static int yy_looking_for_trail_begin = 0;"); 1801 outn ("static int yy_full_lp;"); 1802 outn ("static int *yy_full_state;"); 1803 } 1804 1805 out_hex ("#define YY_TRAILING_MASK 0x%x\n", 1806 (unsigned int) YY_TRAILING_MASK); 1807 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n", 1808 (unsigned int) YY_TRAILING_HEAD_MASK); 1809 } 1810 1811 outn ("#define REJECT \\"); 1812 outn ("{ \\"); 1813 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\"); 1814 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\"); 1815 1816 if (variable_trailing_context_rules) { 1817 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\"); 1818 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\"); 1819 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\"); 1820 } 1821 1822 outn ("++YY_G(yy_lp); \\"); 1823 outn ("goto find_rule; \\"); 1824 1825 outn ("}"); 1826 outn ("]])\n"); 1827 } 1828 1829 else { 1830 outn ("/* The intent behind this definition is that it'll catch"); 1831 outn (" * any uses of REJECT which flex missed."); 1832 outn (" */"); 1833 outn ("#define REJECT reject_used_but_not_detected"); 1834 } 1835 1836 if (yymore_used) { 1837 if (!C_plus_plus) { 1838 if (yytext_is_array) { 1839 if (!reentrant){ 1840 indent_puts ("static int yy_more_offset = 0;"); 1841 indent_puts ("static int yy_prev_more_offset = 0;"); 1842 } 1843 } 1844 else if (!reentrant) { 1845 indent_puts 1846 ("static int yy_more_flag = 0;"); 1847 indent_puts 1848 ("static int yy_more_len = 0;"); 1849 } 1850 } 1851 1852 if (yytext_is_array) { 1853 indent_puts 1854 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))"); 1855 indent_puts ("#define YY_NEED_STRLEN"); 1856 indent_puts ("#define YY_MORE_ADJ 0"); 1857 indent_puts 1858 ("#define YY_RESTORE_YY_MORE_OFFSET \\"); 1859 indent_up (); 1860 indent_puts ("{ \\"); 1861 indent_puts 1862 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\"); 1863 indent_puts ("yyleng -= YY_G(yy_more_offset); \\"); 1864 indent_puts ("}"); 1865 indent_down (); 1866 } 1867 else { 1868 indent_puts 1869 ("#define yymore() (YY_G(yy_more_flag) = 1)"); 1870 indent_puts 1871 ("#define YY_MORE_ADJ YY_G(yy_more_len)"); 1872 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET"); 1873 } 1874 } 1875 1876 else { 1877 indent_puts 1878 ("#define yymore() yymore_used_but_not_detected"); 1879 indent_puts ("#define YY_MORE_ADJ 0"); 1880 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET"); 1881 } 1882 1883 if (!C_plus_plus) { 1884 if (yytext_is_array) { 1885 outn ("#ifndef YYLMAX"); 1886 outn ("#define YYLMAX 8192"); 1887 outn ("#endif\n"); 1888 if (!reentrant){ 1889 outn ("char yytext[YYLMAX];"); 1890 outn ("char *yytext_ptr;"); 1891 } 1892 } 1893 1894 else { 1895 if(! reentrant) 1896 outn ("char *yytext;"); 1897 } 1898 } 1899 1900 out (&action_array[defs1_offset]); 1901 1902 line_directive_out (stdout, 0); 1903 1904 skelout (); /* %% [5.0] - break point in skel */ 1905 1906 if (!C_plus_plus) { 1907 if (use_read) { 1908 outn ("\terrno=0; \\"); 1909 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\"); 1910 outn ("\t{ \\"); 1911 outn ("\t\tif( errno != EINTR) \\"); 1912 outn ("\t\t{ \\"); 1913 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); 1914 outn ("\t\t\tbreak; \\"); 1915 outn ("\t\t} \\"); 1916 outn ("\t\terrno=0; \\"); 1917 outn ("\t\tclearerr(yyin); \\"); 1918 outn ("\t}\\"); 1919 } 1920 1921 else { 1922 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\"); 1923 outn ("\t\t{ \\"); 1924 outn ("\t\tint c = '*'; \\"); 1925 outn ("\t\tsize_t n; \\"); 1926 outn ("\t\tfor ( n = 0; n < max_size && \\"); 1927 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\"); 1928 outn ("\t\t\tbuf[n] = (char) c; \\"); 1929 outn ("\t\tif ( c == '\\n' ) \\"); 1930 outn ("\t\t\tbuf[n++] = (char) c; \\"); 1931 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\"); 1932 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); 1933 outn ("\t\tresult = n; \\"); 1934 outn ("\t\t} \\"); 1935 outn ("\telse \\"); 1936 outn ("\t\t{ \\"); 1937 outn ("\t\terrno=0; \\"); 1938 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\"); 1939 outn ("\t\t\t{ \\"); 1940 outn ("\t\t\tif( errno != EINTR) \\"); 1941 outn ("\t\t\t\t{ \\"); 1942 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); 1943 outn ("\t\t\t\tbreak; \\"); 1944 outn ("\t\t\t\t} \\"); 1945 outn ("\t\t\terrno=0; \\"); 1946 outn ("\t\t\tclearerr(yyin); \\"); 1947 outn ("\t\t\t} \\"); 1948 outn ("\t\t}\\"); 1949 } 1950 } 1951 1952 skelout (); /* %% [6.0] - break point in skel */ 1953 1954 indent_puts ("#define YY_RULE_SETUP \\"); 1955 indent_up (); 1956 if (bol_needed) { 1957 indent_puts ("if ( yyleng > 0 ) \\"); 1958 indent_up (); 1959 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\"); 1960 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\"); 1961 indent_down (); 1962 } 1963 indent_puts ("YY_USER_ACTION"); 1964 indent_down (); 1965 1966 skelout (); /* %% [7.0] - break point in skel */ 1967 1968 /* Copy prolog to output file. */ 1969 out (&action_array[prolog_offset]); 1970 1971 line_directive_out (stdout, 0); 1972 1973 skelout (); /* %% [8.0] - break point in skel */ 1974 1975 set_indent (2); 1976 1977 if (yymore_used && !yytext_is_array) { 1978 indent_puts ("YY_G(yy_more_len) = 0;"); 1979 indent_puts ("if ( YY_G(yy_more_flag) )"); 1980 indent_up (); 1981 indent_puts ("{"); 1982 indent_puts 1983 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);"); 1984 indent_puts ("YY_G(yy_more_flag) = 0;"); 1985 indent_puts ("}"); 1986 indent_down (); 1987 } 1988 1989 skelout (); /* %% [9.0] - break point in skel */ 1990 1991 gen_start_state (); 1992 1993 /* Note, don't use any indentation. */ 1994 outn ("yy_match:"); 1995 gen_next_match (); 1996 1997 skelout (); /* %% [10.0] - break point in skel */ 1998 set_indent (2); 1999 gen_find_action (); 2000 2001 skelout (); /* %% [11.0] - break point in skel */ 2002 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[["); 2003 indent_puts 2004 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )"); 2005 indent_up (); 2006 indent_puts ("{"); 2007 indent_puts ("yy_size_t yyl;"); 2008 do_indent (); 2009 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n", 2010 yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" : 2011 "YY_G(yy_more_len)") : "0"); 2012 indent_up (); 2013 indent_puts ("if ( yytext[yyl] == '\\n' )"); 2014 indent_up (); 2015 indent_puts ("M4_YY_INCR_LINENO();"); 2016 indent_down (); 2017 indent_down (); 2018 indent_puts ("}"); 2019 indent_down (); 2020 outn ("]])"); 2021 2022 skelout (); /* %% [12.0] - break point in skel */ 2023 if (ddebug) { 2024 indent_puts ("if ( yy_flex_debug )"); 2025 indent_up (); 2026 2027 indent_puts ("{"); 2028 indent_puts ("if ( yy_act == 0 )"); 2029 indent_up (); 2030 indent_puts (C_plus_plus ? 2031 "std::cerr << \"--scanner backing up\\n\";" : 2032 "fprintf( stderr, \"--scanner backing up\\n\" );"); 2033 indent_down (); 2034 2035 do_indent (); 2036 out_dec ("else if ( yy_act < %d )\n", num_rules); 2037 indent_up (); 2038 2039 if (C_plus_plus) { 2040 indent_puts 2041 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<"); 2042 indent_puts 2043 (" \"(\\\"\" << yytext << \"\\\")\\n\";"); 2044 } 2045 else { 2046 indent_puts 2047 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\","); 2048 2049 indent_puts 2050 (" (long)yy_rule_linenum[yy_act], yytext );"); 2051 } 2052 2053 indent_down (); 2054 2055 do_indent (); 2056 out_dec ("else if ( yy_act == %d )\n", num_rules); 2057 indent_up (); 2058 2059 if (C_plus_plus) { 2060 indent_puts 2061 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";"); 2062 } 2063 else { 2064 indent_puts 2065 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\","); 2066 indent_puts (" yytext );"); 2067 } 2068 2069 indent_down (); 2070 2071 do_indent (); 2072 out_dec ("else if ( yy_act == %d )\n", num_rules + 1); 2073 indent_up (); 2074 2075 indent_puts (C_plus_plus ? 2076 "std::cerr << \"--(end of buffer or a NUL)\\n\";" : 2077 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );"); 2078 2079 indent_down (); 2080 2081 do_indent (); 2082 outn ("else"); 2083 indent_up (); 2084 2085 if (C_plus_plus) { 2086 indent_puts 2087 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";"); 2088 } 2089 else { 2090 indent_puts 2091 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );"); 2092 } 2093 2094 indent_down (); 2095 2096 indent_puts ("}"); 2097 indent_down (); 2098 } 2099 2100 /* Copy actions to output file. */ 2101 skelout (); /* %% [13.0] - break point in skel */ 2102 indent_up (); 2103 gen_bu_action (); 2104 out (&action_array[action_offset]); 2105 2106 line_directive_out (stdout, 0); 2107 2108 /* generate cases for any missing EOF rules */ 2109 for (i = 1; i <= lastsc; ++i) 2110 if (!sceof[i]) { 2111 do_indent (); 2112 out_str ("case YY_STATE_EOF(%s):\n", scname[i]); 2113 did_eof_rule = true; 2114 } 2115 2116 if (did_eof_rule) { 2117 indent_up (); 2118 indent_puts ("yyterminate();"); 2119 indent_down (); 2120 } 2121 2122 2123 /* Generate code for handling NUL's, if needed. */ 2124 2125 /* First, deal with backing up and setting up yy_cp if the scanner 2126 * finds that it should JAM on the NUL. 2127 */ 2128 skelout (); /* %% [14.0] - break point in skel */ 2129 set_indent (4); 2130 2131 if (fullspd || fulltbl) 2132 indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); 2133 2134 else { /* compressed table */ 2135 if (!reject && !interactive) { 2136 /* Do the guaranteed-needed backing up to figure 2137 * out the match. 2138 */ 2139 indent_puts 2140 ("yy_cp = YY_G(yy_last_accepting_cpos);"); 2141 indent_puts 2142 ("yy_current_state = YY_G(yy_last_accepting_state);"); 2143 } 2144 2145 else 2146 /* Still need to initialize yy_cp, though 2147 * yy_current_state was set up by 2148 * yy_get_previous_state(). 2149 */ 2150 indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); 2151 } 2152 2153 2154 /* Generate code for yy_get_previous_state(). */ 2155 set_indent (1); 2156 skelout (); /* %% [15.0] - break point in skel */ 2157 2158 gen_start_state (); 2159 2160 set_indent (2); 2161 skelout (); /* %% [16.0] - break point in skel */ 2162 gen_next_state (true); 2163 2164 set_indent (1); 2165 skelout (); /* %% [17.0] - break point in skel */ 2166 gen_NUL_trans (); 2167 2168 skelout (); /* %% [18.0] - break point in skel */ 2169 skelout (); /* %% [19.0] - break point in skel */ 2170 /* Update BOL and yylineno inside of input(). */ 2171 if (bol_needed) { 2172 indent_puts 2173 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');"); 2174 if (do_yylineno) { 2175 indent_puts 2176 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )"); 2177 indent_up (); 2178 indent_puts ("M4_YY_INCR_LINENO();"); 2179 indent_down (); 2180 } 2181 } 2182 2183 else if (do_yylineno) { 2184 indent_puts ("if ( c == '\\n' )"); 2185 indent_up (); 2186 indent_puts ("M4_YY_INCR_LINENO();"); 2187 indent_down (); 2188 } 2189 2190 skelout (); 2191 2192 /* Copy remainder of input to output. */ 2193 2194 line_directive_out (stdout, 1); 2195 2196 if (sectnum == 3) { 2197 OUT_BEGIN_CODE (); 2198 (void) flexscan (); /* copy remainder of input to output */ 2199 OUT_END_CODE (); 2200 } 2201 } 2202