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