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

Annotation of src/usr.bin/yacc/skeleton.c, Revision 1.3

1.3     ! niklas      1: /*     $OpenBSD$       */
        !             2:
1.1       deraadt     3: #include "defs.h"
                      4:
                      5: /*  The definition of yysccsid in the banner should be replaced with   */
                      6: /*  a #pragma ident directive if the target C compiler supports                */
                      7: /*  #pragma ident directives.                                          */
                      8: /*                                                                     */
                      9: /*  If the skeleton is changed, the banner should be changed so that   */
                     10: /*  the altered version can be easily distinguished from the original. */
                     11: /*                                                                     */
                     12: /*  The #defines included with the banner are there because they are   */
                     13: /*  useful in subsequent code.  The macros #defined in the header or   */
                     14: /*  the body either are not useful outside of semantic actions or      */
                     15: /*  are conditional.                                                   */
                     16:
                     17: char *banner[] =
                     18: {
                     19:     "#ifndef lint",
                     20:     "/*static char yysccsid[] = \"from: @(#)yaccpar    1.9 (Berkeley) 02/21/93\";*/",
1.3     ! niklas     21:     "static char yyrcsid[] = \"$OpenBSD$\";",
1.1       deraadt    22:     "#endif",
                     23:     "#define YYBYACC 1",
                     24:     "#define YYMAJOR 1",
                     25:     "#define YYMINOR 9",
1.2       niklas     26:     "#define YYLEX yylex()",
                     27:     "#define YYEMPTY -1",
                     28:     "#define yyclearin (yychar=(YYEMPTY))",
1.1       deraadt    29:     "#define yyerrok (yyerrflag=0)",
                     30:     "#define YYRECOVERING (yyerrflag!=0)",
                     31:     0
                     32: };
                     33:
                     34:
                     35: char *tables[] =
                     36: {
                     37:     "extern short yylhs[];",
                     38:     "extern short yylen[];",
                     39:     "extern short yydefred[];",
                     40:     "extern short yydgoto[];",
                     41:     "extern short yysindex[];",
                     42:     "extern short yyrindex[];",
                     43:     "extern short yygindex[];",
                     44:     "extern short yytable[];",
                     45:     "extern short yycheck[];",
                     46:     "#if YYDEBUG",
                     47:     "extern char *yyname[];",
                     48:     "extern char *yyrule[];",
                     49:     "#endif",
                     50:     0
                     51: };
                     52:
                     53:
                     54: char *header[] =
                     55: {
                     56:     "#ifdef YYSTACKSIZE",
                     57:     "#undef YYMAXDEPTH",
                     58:     "#define YYMAXDEPTH YYSTACKSIZE",
                     59:     "#else",
                     60:     "#ifdef YYMAXDEPTH",
                     61:     "#define YYSTACKSIZE YYMAXDEPTH",
                     62:     "#else",
                     63:     "#define YYSTACKSIZE 500",
                     64:     "#define YYMAXDEPTH 500",
                     65:     "#endif",
                     66:     "#endif",
                     67:     "int yydebug;",
                     68:     "int yynerrs;",
                     69:     "int yyerrflag;",
                     70:     "int yychar;",
                     71:     "short *yyssp;",
                     72:     "YYSTYPE *yyvsp;",
                     73:     "YYSTYPE yyval;",
                     74:     "YYSTYPE yylval;",
                     75:     "short yyss[YYSTACKSIZE];",
                     76:     "YYSTYPE yyvs[YYSTACKSIZE];",
                     77:     "#define yystacksize YYSTACKSIZE",
                     78:     0
                     79: };
                     80:
                     81:
                     82: char *body[] =
                     83: {
                     84:     "#define YYABORT goto yyabort",
                     85:     "#define YYREJECT goto yyabort",
                     86:     "#define YYACCEPT goto yyaccept",
                     87:     "#define YYERROR goto yyerrlab",
                     88:     "int",
                     89:     "#if defined(__STDC__)",
                     90:     "yyparse(void)",
                     91:     "#else",
                     92:     "yyparse()",
                     93:     "#endif",
                     94:     "{",
                     95:     "    register int yym, yyn, yystate;",
                     96:     "#if YYDEBUG",
                     97:     "    register char *yys;",
                     98:     "    extern char *getenv();",
                     99:     "",
                    100:     "    if (yys = getenv(\"YYDEBUG\"))",
                    101:     "    {",
                    102:     "        yyn = *yys;",
                    103:     "        if (yyn >= '0' && yyn <= '9')",
                    104:     "            yydebug = yyn - '0';",
                    105:     "    }",
                    106:     "#endif",
                    107:     "",
                    108:     "    yynerrs = 0;",
                    109:     "    yyerrflag = 0;",
                    110:     "    yychar = (-1);",
                    111:     "",
                    112:     "    yyssp = yyss;",
                    113:     "    yyvsp = yyvs;",
                    114:     "    *yyssp = yystate = 0;",
                    115:     "",
                    116:     "yyloop:",
                    117:     "    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
                    118:     "    if (yychar < 0)",
                    119:     "    {",
                    120:     "        if ((yychar = yylex()) < 0) yychar = 0;",
                    121:     "#if YYDEBUG",
                    122:     "        if (yydebug)",
                    123:     "        {",
                    124:     "            yys = 0;",
                    125:     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
                    126:     "            if (!yys) yys = \"illegal-symbol\";",
                    127:     "            printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
                    128:     "                    YYPREFIX, yystate, yychar, yys);",
                    129:     "        }",
                    130:     "#endif",
                    131:     "    }",
                    132:     "    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
                    133:     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
                    134:     "    {",
                    135:     "#if YYDEBUG",
                    136:     "        if (yydebug)",
                    137:     "            printf(\"%sdebug: state %d, shifting to state %d\\n\",",
                    138:     "                    YYPREFIX, yystate, yytable[yyn]);",
                    139:     "#endif",
                    140:     "        if (yyssp >= yyss + yystacksize - 1)",
                    141:     "        {",
                    142:     "            goto yyoverflow;",
                    143:     "        }",
                    144:     "        *++yyssp = yystate = yytable[yyn];",
                    145:     "        *++yyvsp = yylval;",
                    146:     "        yychar = (-1);",
                    147:     "        if (yyerrflag > 0)  --yyerrflag;",
                    148:     "        goto yyloop;",
                    149:     "    }",
                    150:     "    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
                    151:     "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
                    152:     "    {",
                    153:     "        yyn = yytable[yyn];",
                    154:     "        goto yyreduce;",
                    155:     "    }",
                    156:     "    if (yyerrflag) goto yyinrecovery;",
                    157:     "    yyerror(\"syntax error\");",
                    158:     "#ifdef lint",
                    159:     "    goto yyerrlab;",
                    160:     "#endif",
                    161:     "yyerrlab:",
                    162:     "    ++yynerrs;",
                    163:     "yyinrecovery:",
                    164:     "    if (yyerrflag < 3)",
                    165:     "    {",
                    166:     "        yyerrflag = 3;",
                    167:     "        for (;;)",
                    168:     "        {",
                    169:     "            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
                    170:     "                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
                    171:     "            {",
                    172:     "#if YYDEBUG",
                    173:     "                if (yydebug)",
                    174:     "                    printf(\"%sdebug: state %d, error recovery shifting\\",
                    175:     " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
                    176:     "#endif",
                    177:     "                if (yyssp >= yyss + yystacksize - 1)",
                    178:     "                {",
                    179:     "                    goto yyoverflow;",
                    180:     "                }",
                    181:     "                *++yyssp = yystate = yytable[yyn];",
                    182:     "                *++yyvsp = yylval;",
                    183:     "                goto yyloop;",
                    184:     "            }",
                    185:     "            else",
                    186:     "            {",
                    187:     "#if YYDEBUG",
                    188:     "                if (yydebug)",
                    189:     "                    printf(\"%sdebug: error recovery discarding state %d\
                    190: \\n\",",
                    191:     "                            YYPREFIX, *yyssp);",
                    192:     "#endif",
                    193:     "                if (yyssp <= yyss) goto yyabort;",
                    194:     "                --yyssp;",
                    195:     "                --yyvsp;",
                    196:     "            }",
                    197:     "        }",
                    198:     "    }",
                    199:     "    else",
                    200:     "    {",
                    201:     "        if (yychar == 0) goto yyabort;",
                    202:     "#if YYDEBUG",
                    203:     "        if (yydebug)",
                    204:     "        {",
                    205:     "            yys = 0;",
                    206:     "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
                    207:     "            if (!yys) yys = \"illegal-symbol\";",
                    208:     "            printf(\"%sdebug: state %d, error recovery discards token %d\
                    209:  (%s)\\n\",",
                    210:     "                    YYPREFIX, yystate, yychar, yys);",
                    211:     "        }",
                    212:     "#endif",
                    213:     "        yychar = (-1);",
                    214:     "        goto yyloop;",
                    215:     "    }",
                    216:     "yyreduce:",
                    217:     "#if YYDEBUG",
                    218:     "    if (yydebug)",
                    219:     "        printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
                    220:     "                YYPREFIX, yystate, yyn, yyrule[yyn]);",
                    221:     "#endif",
                    222:     "    yym = yylen[yyn];",
                    223:     "    yyval = yyvsp[1-yym];",
                    224:     "    switch (yyn)",
                    225:     "    {",
                    226:     0
                    227: };
                    228:
                    229:
                    230: char *trailer[] =
                    231: {
                    232:     "    }",
                    233:     "    yyssp -= yym;",
                    234:     "    yystate = *yyssp;",
                    235:     "    yyvsp -= yym;",
                    236:     "    yym = yylhs[yyn];",
                    237:     "    if (yystate == 0 && yym == 0)",
                    238:     "    {",
                    239:     "#if YYDEBUG",
                    240:     "        if (yydebug)",
                    241:     "            printf(\"%sdebug: after reduction, shifting from state 0 to\\",
                    242:     " state %d\\n\", YYPREFIX, YYFINAL);",
                    243:     "#endif",
                    244:     "        yystate = YYFINAL;",
                    245:     "        *++yyssp = YYFINAL;",
                    246:     "        *++yyvsp = yyval;",
                    247:     "        if (yychar < 0)",
                    248:     "        {",
                    249:     "            if ((yychar = yylex()) < 0) yychar = 0;",
                    250:     "#if YYDEBUG",
                    251:     "            if (yydebug)",
                    252:     "            {",
                    253:     "                yys = 0;",
                    254:     "                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
                    255:     "                if (!yys) yys = \"illegal-symbol\";",
                    256:     "                printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
                    257:     "                        YYPREFIX, YYFINAL, yychar, yys);",
                    258:     "            }",
                    259:     "#endif",
                    260:     "        }",
                    261:     "        if (yychar == 0) goto yyaccept;",
                    262:     "        goto yyloop;",
                    263:     "    }",
                    264:     "    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
                    265:     "            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
                    266:     "        yystate = yytable[yyn];",
                    267:     "    else",
                    268:     "        yystate = yydgoto[yym];",
                    269:     "#if YYDEBUG",
                    270:     "    if (yydebug)",
                    271:     "        printf(\"%sdebug: after reduction, shifting from state %d \\",
                    272:     "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
                    273:     "#endif",
                    274:     "    if (yyssp >= yyss + yystacksize - 1)",
                    275:     "    {",
                    276:     "        goto yyoverflow;",
                    277:     "    }",
                    278:     "    *++yyssp = yystate;",
                    279:     "    *++yyvsp = yyval;",
                    280:     "    goto yyloop;",
                    281:     "yyoverflow:",
                    282:     "    yyerror(\"yacc stack overflow\");",
                    283:     "yyabort:",
                    284:     "    return (1);",
                    285:     "yyaccept:",
                    286:     "    return (0);",
                    287:     "}",
                    288:     0
                    289: };
                    290:
                    291:
                    292: write_section(section)
                    293: char *section[];
                    294: {
                    295:     register int c;
                    296:     register int i;
                    297:     register char *s;
                    298:     register FILE *f;
                    299:
                    300:     f = code_file;
                    301:     for (i = 0; s = section[i]; ++i)
                    302:     {
                    303:        ++outline;
                    304:        while (c = *s)
                    305:        {
                    306:            putc(c, f);
                    307:            ++s;
                    308:        }
                    309:        putc('\n', f);
                    310:     }
                    311: }