[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.2

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