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