[BACK]Return to gen.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / lex

Annotation of src/usr.bin/lex/gen.c, Revision 1.13

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