Home | History | Annotate | Line # | Download | only in yacc
calc2.tab.c revision 1.5
      1  1.4  christos /*	$NetBSD: calc2.tab.c,v 1.5 2024/09/14 21:29:04 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /* original parser id follows */
      4  1.1  christos /* yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93" */
      5  1.1  christos /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
      6  1.1  christos 
      7  1.1  christos #define YYBYACC 1
      8  1.4  christos #define YYMAJOR 2
      9  1.4  christos #define YYMINOR 0
     10  1.1  christos #define YYCHECK "yyyymmdd"
     11  1.1  christos 
     12  1.1  christos #define YYEMPTY        (-1)
     13  1.1  christos #define yyclearin      (yychar = YYEMPTY)
     14  1.1  christos #define yyerrok        (yyerrflag = 0)
     15  1.1  christos #define YYRECOVERING() (yyerrflag != 0)
     16  1.1  christos #define YYENOMEM       (-2)
     17  1.1  christos #define YYEOF          0
     18  1.1  christos 
     19  1.1  christos #ifndef yyparse
     20  1.1  christos #define yyparse    calc2_parse
     21  1.1  christos #endif /* yyparse */
     22  1.1  christos 
     23  1.1  christos #ifndef yylex
     24  1.1  christos #define yylex      calc2_lex
     25  1.1  christos #endif /* yylex */
     26  1.1  christos 
     27  1.1  christos #ifndef yyerror
     28  1.1  christos #define yyerror    calc2_error
     29  1.1  christos #endif /* yyerror */
     30  1.1  christos 
     31  1.1  christos #ifndef yychar
     32  1.1  christos #define yychar     calc2_char
     33  1.1  christos #endif /* yychar */
     34  1.1  christos 
     35  1.1  christos #ifndef yyval
     36  1.1  christos #define yyval      calc2_val
     37  1.1  christos #endif /* yyval */
     38  1.1  christos 
     39  1.1  christos #ifndef yylval
     40  1.1  christos #define yylval     calc2_lval
     41  1.1  christos #endif /* yylval */
     42  1.1  christos 
     43  1.1  christos #ifndef yydebug
     44  1.1  christos #define yydebug    calc2_debug
     45  1.1  christos #endif /* yydebug */
     46  1.1  christos 
     47  1.1  christos #ifndef yynerrs
     48  1.1  christos #define yynerrs    calc2_nerrs
     49  1.1  christos #endif /* yynerrs */
     50  1.1  christos 
     51  1.1  christos #ifndef yyerrflag
     52  1.1  christos #define yyerrflag  calc2_errflag
     53  1.1  christos #endif /* yyerrflag */
     54  1.1  christos 
     55  1.1  christos #ifndef yylhs
     56  1.1  christos #define yylhs      calc2_lhs
     57  1.1  christos #endif /* yylhs */
     58  1.1  christos 
     59  1.1  christos #ifndef yylen
     60  1.1  christos #define yylen      calc2_len
     61  1.1  christos #endif /* yylen */
     62  1.1  christos 
     63  1.1  christos #ifndef yydefred
     64  1.1  christos #define yydefred   calc2_defred
     65  1.1  christos #endif /* yydefred */
     66  1.1  christos 
     67  1.1  christos #ifndef yydgoto
     68  1.1  christos #define yydgoto    calc2_dgoto
     69  1.1  christos #endif /* yydgoto */
     70  1.1  christos 
     71  1.1  christos #ifndef yysindex
     72  1.1  christos #define yysindex   calc2_sindex
     73  1.1  christos #endif /* yysindex */
     74  1.1  christos 
     75  1.1  christos #ifndef yyrindex
     76  1.1  christos #define yyrindex   calc2_rindex
     77  1.1  christos #endif /* yyrindex */
     78  1.1  christos 
     79  1.1  christos #ifndef yygindex
     80  1.1  christos #define yygindex   calc2_gindex
     81  1.1  christos #endif /* yygindex */
     82  1.1  christos 
     83  1.1  christos #ifndef yytable
     84  1.1  christos #define yytable    calc2_table
     85  1.1  christos #endif /* yytable */
     86  1.1  christos 
     87  1.1  christos #ifndef yycheck
     88  1.1  christos #define yycheck    calc2_check
     89  1.1  christos #endif /* yycheck */
     90  1.1  christos 
     91  1.1  christos #ifndef yyname
     92  1.1  christos #define yyname     calc2_name
     93  1.1  christos #endif /* yyname */
     94  1.1  christos 
     95  1.1  christos #ifndef yyrule
     96  1.1  christos #define yyrule     calc2_rule
     97  1.1  christos #endif /* yyrule */
     98  1.1  christos #define YYPREFIX "calc2_"
     99  1.1  christos 
    100  1.1  christos #define YYPURE 0
    101  1.1  christos 
    102  1.1  christos #line 7 "calc2.y"
    103  1.1  christos # include <stdio.h>
    104  1.1  christos # include <ctype.h>
    105  1.1  christos 
    106  1.1  christos #ifdef YYBISON
    107  1.1  christos #define YYLEX_PARAM base
    108  1.1  christos #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
    109  1.1  christos #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
    110  1.1  christos int YYLEX_DECL();
    111  1.1  christos static void YYERROR_DECL();
    112  1.1  christos #endif
    113  1.1  christos 
    114  1.1  christos #line 113 "calc2.tab.c"
    115  1.1  christos 
    116  1.1  christos #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
    117  1.1  christos /* Default: YYSTYPE is the semantic value type. */
    118  1.1  christos typedef int YYSTYPE;
    119  1.1  christos # define YYSTYPE_IS_DECLARED 1
    120  1.1  christos #endif
    121  1.1  christos 
    122  1.1  christos /* compatibility with bison */
    123  1.1  christos #ifdef YYPARSE_PARAM
    124  1.1  christos /* compatibility with FreeBSD */
    125  1.1  christos # ifdef YYPARSE_PARAM_TYPE
    126  1.1  christos #  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
    127  1.1  christos # else
    128  1.1  christos #  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
    129  1.1  christos # endif
    130  1.1  christos #else
    131  1.1  christos # define YYPARSE_DECL() yyparse(int regs[26], int *base)
    132  1.1  christos #endif
    133  1.1  christos 
    134  1.1  christos /* Parameters sent to lex. */
    135  1.1  christos #ifdef YYLEX_PARAM
    136  1.1  christos # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
    137  1.1  christos # define YYLEX yylex(YYLEX_PARAM)
    138  1.1  christos #else
    139  1.1  christos # define YYLEX_DECL() yylex(int *base)
    140  1.1  christos # define YYLEX yylex(base)
    141  1.1  christos #endif
    142  1.1  christos 
    143  1.1  christos /* Parameters sent to yyerror. */
    144  1.1  christos #ifndef YYERROR_DECL
    145  1.1  christos #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
    146  1.1  christos #endif
    147  1.1  christos #ifndef YYERROR_CALL
    148  1.1  christos #define YYERROR_CALL(msg) yyerror(regs, base, msg)
    149  1.1  christos #endif
    150  1.1  christos 
    151  1.1  christos extern int YYPARSE_DECL();
    152  1.1  christos 
    153  1.1  christos #define DIGIT 257
    154  1.1  christos #define LETTER 258
    155  1.1  christos #define UMINUS 259
    156  1.1  christos #define YYERRCODE 256
    157  1.5  christos typedef int YYINT;
    158  1.1  christos static const YYINT calc2_lhs[] = {                       -1,
    159  1.1  christos     0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
    160  1.1  christos     2,    2,    2,    2,    2,    2,    3,    3,
    161  1.1  christos };
    162  1.1  christos static const YYINT calc2_len[] = {                        2,
    163  1.1  christos     0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
    164  1.1  christos     3,    3,    3,    2,    1,    1,    1,    2,
    165  1.1  christos };
    166  1.1  christos static const YYINT calc2_defred[] = {                     1,
    167  1.1  christos     0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
    168  1.1  christos     0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
    169  1.1  christos     0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
    170  1.1  christos    10,   11,
    171  1.1  christos };
    172  1.1  christos static const YYINT calc2_dgoto[] = {                      1,
    173  1.1  christos     7,    8,    9,
    174  1.1  christos };
    175  1.1  christos static const YYINT calc2_sindex[] = {                     0,
    176  1.1  christos   -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
    177  1.1  christos   -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
    178  1.1  christos   -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
    179  1.1  christos     0,    0,
    180  1.1  christos };
    181  1.1  christos static const YYINT calc2_rindex[] = {                     0,
    182  1.1  christos     0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
    183  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    184  1.1  christos     0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
    185  1.1  christos     0,    0,
    186  1.1  christos };
    187  1.1  christos static const YYINT calc2_gindex[] = {                     0,
    188  1.1  christos     0,   65,    0,
    189  1.1  christos };
    190  1.1  christos #define YYTABLESIZE 220
    191  1.1  christos static const YYINT calc2_table[] = {                      6,
    192  1.1  christos    16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
    193  1.1  christos    15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
    194  1.1  christos     0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
    195  1.1  christos     0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
    196  1.1  christos     0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
    197  1.1  christos     8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
    198  1.1  christos     0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
    199  1.1  christos    14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
    200  1.1  christos    26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
    201  1.1  christos     0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
    202  1.1  christos     0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
    203  1.1  christos     0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
    204  1.1  christos     0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
    205  1.1  christos     0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
    206  1.1  christos     0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
    207  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    208  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    209  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    210  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    211  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    212  1.1  christos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    213  1.1  christos     0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
    214  1.1  christos };
    215  1.1  christos static const YYINT calc2_check[] = {                     40,
    216  1.1  christos    10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
    217  1.1  christos    10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
    218  1.1  christos    -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
    219  1.1  christos    -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
    220  1.1  christos    -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
    221  1.1  christos    38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
    222  1.1  christos    -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
    223  1.1  christos     6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
    224  1.1  christos    16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
    225  1.1  christos    -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
    226  1.1  christos    -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
    227  1.1  christos    -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
    228  1.1  christos    -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
    229  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
    230  1.1  christos    -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
    231  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    232  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    233  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    234  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    235  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    236  1.1  christos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
    237  1.1  christos    -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
    238  1.1  christos };
    239  1.1  christos #define YYFINAL 1
    240  1.1  christos #ifndef YYDEBUG
    241  1.1  christos #define YYDEBUG 0
    242  1.1  christos #endif
    243  1.1  christos #define YYMAXTOKEN 259
    244  1.1  christos #define YYUNDFTOKEN 265
    245  1.1  christos #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
    246  1.1  christos #if YYDEBUG
    247  1.1  christos static const char *const calc2_name[] = {
    248  1.1  christos 
    249  1.1  christos "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    250  1.1  christos 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
    251  1.1  christos 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    252  1.1  christos 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
    253  1.1  christos 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    254  1.1  christos 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    255  1.1  christos 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    256  1.1  christos 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",0,0,0,0,0,"illegal-symbol",
    257  1.1  christos };
    258  1.1  christos static const char *const calc2_rule[] = {
    259  1.1  christos "$accept : list",
    260  1.1  christos "list :",
    261  1.1  christos "list : list stat '\\n'",
    262  1.1  christos "list : list error '\\n'",
    263  1.1  christos "stat : expr",
    264  1.1  christos "stat : LETTER '=' expr",
    265  1.1  christos "expr : '(' expr ')'",
    266  1.1  christos "expr : expr '+' expr",
    267  1.1  christos "expr : expr '-' expr",
    268  1.1  christos "expr : expr '*' expr",
    269  1.1  christos "expr : expr '/' expr",
    270  1.1  christos "expr : expr '%' expr",
    271  1.1  christos "expr : expr '&' expr",
    272  1.1  christos "expr : expr '|' expr",
    273  1.1  christos "expr : '-' expr",
    274  1.1  christos "expr : LETTER",
    275  1.1  christos "expr : number",
    276  1.1  christos "number : DIGIT",
    277  1.1  christos "number : number DIGIT",
    278  1.1  christos 
    279  1.1  christos };
    280  1.1  christos #endif
    281  1.1  christos 
    282  1.3  christos #if YYDEBUG
    283  1.1  christos int      yydebug;
    284  1.3  christos #endif
    285  1.1  christos 
    286  1.1  christos int      yyerrflag;
    287  1.1  christos int      yychar;
    288  1.1  christos YYSTYPE  yyval;
    289  1.1  christos YYSTYPE  yylval;
    290  1.3  christos int      yynerrs;
    291  1.1  christos 
    292  1.1  christos /* define the initial stack-sizes */
    293  1.1  christos #ifdef YYSTACKSIZE
    294  1.1  christos #undef YYMAXDEPTH
    295  1.1  christos #define YYMAXDEPTH  YYSTACKSIZE
    296  1.1  christos #else
    297  1.1  christos #ifdef YYMAXDEPTH
    298  1.1  christos #define YYSTACKSIZE YYMAXDEPTH
    299  1.1  christos #else
    300  1.1  christos #define YYSTACKSIZE 10000
    301  1.1  christos #define YYMAXDEPTH  10000
    302  1.1  christos #endif
    303  1.1  christos #endif
    304  1.1  christos 
    305  1.1  christos #define YYINITSTACKSIZE 200
    306  1.1  christos 
    307  1.1  christos typedef struct {
    308  1.1  christos     unsigned stacksize;
    309  1.1  christos     YYINT    *s_base;
    310  1.1  christos     YYINT    *s_mark;
    311  1.1  christos     YYINT    *s_last;
    312  1.1  christos     YYSTYPE  *l_base;
    313  1.1  christos     YYSTYPE  *l_mark;
    314  1.1  christos } YYSTACKDATA;
    315  1.1  christos /* variables for the parser stack */
    316  1.1  christos static YYSTACKDATA yystack;
    317  1.1  christos #line 73 "calc2.y"
    318  1.1  christos  /* start of programs */
    319  1.1  christos 
    320  1.1  christos #ifdef YYBYACC
    321  1.1  christos extern int YYLEX_DECL();
    322  1.1  christos #endif
    323  1.1  christos 
    324  1.1  christos int
    325  1.1  christos main (void)
    326  1.1  christos {
    327  1.1  christos     int regs[26];
    328  1.1  christos     int base = 10;
    329  1.1  christos 
    330  1.1  christos     while(!feof(stdin)) {
    331  1.1  christos 	yyparse(regs, &base);
    332  1.1  christos     }
    333  1.1  christos     return 0;
    334  1.1  christos }
    335  1.1  christos 
    336  1.1  christos #define UNUSED(x) ((void)(x))
    337  1.1  christos 
    338  1.1  christos static void
    339  1.1  christos YYERROR_DECL()
    340  1.1  christos {
    341  1.1  christos     UNUSED(regs); /* %parse-param regs is not actually used here */
    342  1.1  christos     UNUSED(base); /* %parse-param base is not actually used here */
    343  1.1  christos     fprintf(stderr, "%s\n", s);
    344  1.1  christos }
    345  1.1  christos 
    346  1.1  christos int
    347  1.1  christos YYLEX_DECL()
    348  1.1  christos {
    349  1.1  christos 	/* lexical analysis routine */
    350  1.1  christos 	/* returns LETTER for a lower case letter, yylval = 0 through 25 */
    351  1.1  christos 	/* return DIGIT for a digit, yylval = 0 through 9 */
    352  1.1  christos 	/* all other characters are returned immediately */
    353  1.1  christos 
    354  1.1  christos     int c;
    355  1.1  christos 
    356  1.1  christos     while( (c=getchar()) == ' ' )   { /* skip blanks */ }
    357  1.1  christos 
    358  1.1  christos     /* c is now nonblank */
    359  1.1  christos 
    360  1.1  christos     if( islower( c )) {
    361  1.1  christos 	yylval = c - 'a';
    362  1.1  christos 	return ( LETTER );
    363  1.1  christos     }
    364  1.1  christos     if( isdigit( c )) {
    365  1.1  christos 	yylval = (c - '0') % (*base);
    366  1.1  christos 	return ( DIGIT );
    367  1.1  christos     }
    368  1.1  christos     return( c );
    369  1.1  christos }
    370  1.3  christos #line 369 "calc2.tab.c"
    371  1.1  christos 
    372  1.1  christos #if YYDEBUG
    373  1.2  christos #include <stdio.h>	/* needed for printf */
    374  1.1  christos #endif
    375  1.1  christos 
    376  1.1  christos #include <stdlib.h>	/* needed for malloc, etc */
    377  1.1  christos #include <string.h>	/* needed for memset */
    378  1.1  christos 
    379  1.1  christos /* allocate initial stack or double stack size, up to YYMAXDEPTH */
    380  1.1  christos static int yygrowstack(YYSTACKDATA *data)
    381  1.1  christos {
    382  1.1  christos     int i;
    383  1.1  christos     unsigned newsize;
    384  1.1  christos     YYINT *newss;
    385  1.1  christos     YYSTYPE *newvs;
    386  1.1  christos 
    387  1.1  christos     if ((newsize = data->stacksize) == 0)
    388  1.1  christos         newsize = YYINITSTACKSIZE;
    389  1.1  christos     else if (newsize >= YYMAXDEPTH)
    390  1.1  christos         return YYENOMEM;
    391  1.1  christos     else if ((newsize *= 2) > YYMAXDEPTH)
    392  1.1  christos         newsize = YYMAXDEPTH;
    393  1.1  christos 
    394  1.1  christos     i = (int) (data->s_mark - data->s_base);
    395  1.1  christos     newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
    396  1.1  christos     if (newss == 0)
    397  1.1  christos         return YYENOMEM;
    398  1.1  christos 
    399  1.1  christos     data->s_base = newss;
    400  1.1  christos     data->s_mark = newss + i;
    401  1.1  christos 
    402  1.1  christos     newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
    403  1.1  christos     if (newvs == 0)
    404  1.1  christos         return YYENOMEM;
    405  1.1  christos 
    406  1.1  christos     data->l_base = newvs;
    407  1.1  christos     data->l_mark = newvs + i;
    408  1.1  christos 
    409  1.1  christos     data->stacksize = newsize;
    410  1.1  christos     data->s_last = data->s_base + newsize - 1;
    411  1.1  christos     return 0;
    412  1.1  christos }
    413  1.1  christos 
    414  1.1  christos #if YYPURE || defined(YY_NO_LEAKS)
    415  1.1  christos static void yyfreestack(YYSTACKDATA *data)
    416  1.1  christos {
    417  1.1  christos     free(data->s_base);
    418  1.1  christos     free(data->l_base);
    419  1.1  christos     memset(data, 0, sizeof(*data));
    420  1.1  christos }
    421  1.1  christos #else
    422  1.1  christos #define yyfreestack(data) /* nothing */
    423  1.1  christos #endif
    424  1.1  christos 
    425  1.1  christos #define YYABORT  goto yyabort
    426  1.1  christos #define YYREJECT goto yyabort
    427  1.1  christos #define YYACCEPT goto yyaccept
    428  1.1  christos #define YYERROR  goto yyerrlab
    429  1.1  christos 
    430  1.1  christos int
    431  1.1  christos YYPARSE_DECL()
    432  1.1  christos {
    433  1.1  christos     int yym, yyn, yystate;
    434  1.1  christos #if YYDEBUG
    435  1.1  christos     const char *yys;
    436  1.1  christos 
    437  1.1  christos     if ((yys = getenv("YYDEBUG")) != 0)
    438  1.1  christos     {
    439  1.1  christos         yyn = *yys;
    440  1.1  christos         if (yyn >= '0' && yyn <= '9')
    441  1.1  christos             yydebug = yyn - '0';
    442  1.1  christos     }
    443  1.1  christos #endif
    444  1.1  christos 
    445  1.5  christos     /* yym is set below */
    446  1.5  christos     /* yyn is set below */
    447  1.1  christos     yynerrs = 0;
    448  1.1  christos     yyerrflag = 0;
    449  1.1  christos     yychar = YYEMPTY;
    450  1.1  christos     yystate = 0;
    451  1.1  christos 
    452  1.1  christos #if YYPURE
    453  1.1  christos     memset(&yystack, 0, sizeof(yystack));
    454  1.1  christos #endif
    455  1.1  christos 
    456  1.1  christos     if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
    457  1.1  christos     yystack.s_mark = yystack.s_base;
    458  1.1  christos     yystack.l_mark = yystack.l_base;
    459  1.1  christos     yystate = 0;
    460  1.1  christos     *yystack.s_mark = 0;
    461  1.1  christos 
    462  1.1  christos yyloop:
    463  1.1  christos     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
    464  1.1  christos     if (yychar < 0)
    465  1.1  christos     {
    466  1.2  christos         yychar = YYLEX;
    467  1.2  christos         if (yychar < 0) yychar = YYEOF;
    468  1.1  christos #if YYDEBUG
    469  1.1  christos         if (yydebug)
    470  1.1  christos         {
    471  1.2  christos             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
    472  1.1  christos             printf("%sdebug: state %d, reading %d (%s)\n",
    473  1.1  christos                     YYPREFIX, yystate, yychar, yys);
    474  1.1  christos         }
    475  1.1  christos #endif
    476  1.1  christos     }
    477  1.2  christos     if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
    478  1.2  christos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
    479  1.1  christos     {
    480  1.1  christos #if YYDEBUG
    481  1.1  christos         if (yydebug)
    482  1.1  christos             printf("%sdebug: state %d, shifting to state %d\n",
    483  1.1  christos                     YYPREFIX, yystate, yytable[yyn]);
    484  1.1  christos #endif
    485  1.2  christos         if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
    486  1.1  christos         yystate = yytable[yyn];
    487  1.1  christos         *++yystack.s_mark = yytable[yyn];
    488  1.1  christos         *++yystack.l_mark = yylval;
    489  1.1  christos         yychar = YYEMPTY;
    490  1.1  christos         if (yyerrflag > 0)  --yyerrflag;
    491  1.1  christos         goto yyloop;
    492  1.1  christos     }
    493  1.2  christos     if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
    494  1.2  christos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
    495  1.1  christos     {
    496  1.1  christos         yyn = yytable[yyn];
    497  1.1  christos         goto yyreduce;
    498  1.1  christos     }
    499  1.2  christos     if (yyerrflag != 0) goto yyinrecovery;
    500  1.1  christos 
    501  1.1  christos     YYERROR_CALL("syntax error");
    502  1.1  christos 
    503  1.2  christos     goto yyerrlab; /* redundant goto avoids 'unused label' warning */
    504  1.1  christos yyerrlab:
    505  1.1  christos     ++yynerrs;
    506  1.1  christos 
    507  1.1  christos yyinrecovery:
    508  1.1  christos     if (yyerrflag < 3)
    509  1.1  christos     {
    510  1.1  christos         yyerrflag = 3;
    511  1.1  christos         for (;;)
    512  1.1  christos         {
    513  1.2  christos             if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
    514  1.2  christos                     yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
    515  1.1  christos             {
    516  1.1  christos #if YYDEBUG
    517  1.1  christos                 if (yydebug)
    518  1.1  christos                     printf("%sdebug: state %d, error recovery shifting\
    519  1.1  christos  to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
    520  1.1  christos #endif
    521  1.2  christos                 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
    522  1.1  christos                 yystate = yytable[yyn];
    523  1.1  christos                 *++yystack.s_mark = yytable[yyn];
    524  1.1  christos                 *++yystack.l_mark = yylval;
    525  1.1  christos                 goto yyloop;
    526  1.1  christos             }
    527  1.1  christos             else
    528  1.1  christos             {
    529  1.1  christos #if YYDEBUG
    530  1.1  christos                 if (yydebug)
    531  1.1  christos                     printf("%sdebug: error recovery discarding state %d\n",
    532  1.1  christos                             YYPREFIX, *yystack.s_mark);
    533  1.1  christos #endif
    534  1.1  christos                 if (yystack.s_mark <= yystack.s_base) goto yyabort;
    535  1.1  christos                 --yystack.s_mark;
    536  1.1  christos                 --yystack.l_mark;
    537  1.1  christos             }
    538  1.1  christos         }
    539  1.1  christos     }
    540  1.1  christos     else
    541  1.1  christos     {
    542  1.1  christos         if (yychar == YYEOF) goto yyabort;
    543  1.1  christos #if YYDEBUG
    544  1.1  christos         if (yydebug)
    545  1.1  christos         {
    546  1.2  christos             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
    547  1.1  christos             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
    548  1.1  christos                     YYPREFIX, yystate, yychar, yys);
    549  1.1  christos         }
    550  1.1  christos #endif
    551  1.1  christos         yychar = YYEMPTY;
    552  1.1  christos         goto yyloop;
    553  1.1  christos     }
    554  1.1  christos 
    555  1.1  christos yyreduce:
    556  1.1  christos #if YYDEBUG
    557  1.1  christos     if (yydebug)
    558  1.1  christos         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
    559  1.1  christos                 YYPREFIX, yystate, yyn, yyrule[yyn]);
    560  1.1  christos #endif
    561  1.1  christos     yym = yylen[yyn];
    562  1.2  christos     if (yym > 0)
    563  1.1  christos         yyval = yystack.l_mark[1-yym];
    564  1.1  christos     else
    565  1.1  christos         memset(&yyval, 0, sizeof yyval);
    566  1.2  christos 
    567  1.1  christos     switch (yyn)
    568  1.1  christos     {
    569  1.1  christos case 3:
    570  1.1  christos #line 35 "calc2.y"
    571  1.1  christos 	{  yyerrok ; }
    572  1.5  christos #line 571 "calc2.tab.c"
    573  1.1  christos break;
    574  1.1  christos case 4:
    575  1.1  christos #line 39 "calc2.y"
    576  1.1  christos 	{  printf("%d\n",yystack.l_mark[0]);}
    577  1.5  christos #line 576 "calc2.tab.c"
    578  1.1  christos break;
    579  1.1  christos case 5:
    580  1.1  christos #line 41 "calc2.y"
    581  1.1  christos 	{  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
    582  1.5  christos #line 581 "calc2.tab.c"
    583  1.1  christos break;
    584  1.1  christos case 6:
    585  1.1  christos #line 45 "calc2.y"
    586  1.1  christos 	{  yyval = yystack.l_mark[-1]; }
    587  1.5  christos #line 586 "calc2.tab.c"
    588  1.1  christos break;
    589  1.1  christos case 7:
    590  1.1  christos #line 47 "calc2.y"
    591  1.1  christos 	{  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
    592  1.5  christos #line 591 "calc2.tab.c"
    593  1.1  christos break;
    594  1.1  christos case 8:
    595  1.1  christos #line 49 "calc2.y"
    596  1.1  christos 	{  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
    597  1.5  christos #line 596 "calc2.tab.c"
    598  1.1  christos break;
    599  1.1  christos case 9:
    600  1.1  christos #line 51 "calc2.y"
    601  1.1  christos 	{  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
    602  1.5  christos #line 601 "calc2.tab.c"
    603  1.1  christos break;
    604  1.1  christos case 10:
    605  1.1  christos #line 53 "calc2.y"
    606  1.1  christos 	{  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
    607  1.5  christos #line 606 "calc2.tab.c"
    608  1.1  christos break;
    609  1.1  christos case 11:
    610  1.1  christos #line 55 "calc2.y"
    611  1.1  christos 	{  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
    612  1.5  christos #line 611 "calc2.tab.c"
    613  1.1  christos break;
    614  1.1  christos case 12:
    615  1.1  christos #line 57 "calc2.y"
    616  1.1  christos 	{  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
    617  1.5  christos #line 616 "calc2.tab.c"
    618  1.1  christos break;
    619  1.1  christos case 13:
    620  1.1  christos #line 59 "calc2.y"
    621  1.1  christos 	{  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
    622  1.5  christos #line 621 "calc2.tab.c"
    623  1.1  christos break;
    624  1.1  christos case 14:
    625  1.1  christos #line 61 "calc2.y"
    626  1.1  christos 	{  yyval = - yystack.l_mark[0]; }
    627  1.5  christos #line 626 "calc2.tab.c"
    628  1.1  christos break;
    629  1.1  christos case 15:
    630  1.1  christos #line 63 "calc2.y"
    631  1.1  christos 	{  yyval = regs[yystack.l_mark[0]]; }
    632  1.5  christos #line 631 "calc2.tab.c"
    633  1.1  christos break;
    634  1.1  christos case 17:
    635  1.1  christos #line 68 "calc2.y"
    636  1.1  christos 	{  yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
    637  1.5  christos #line 636 "calc2.tab.c"
    638  1.1  christos break;
    639  1.1  christos case 18:
    640  1.1  christos #line 70 "calc2.y"
    641  1.1  christos 	{  yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
    642  1.5  christos #line 641 "calc2.tab.c"
    643  1.1  christos break;
    644  1.5  christos #line 643 "calc2.tab.c"
    645  1.1  christos     }
    646  1.1  christos     yystack.s_mark -= yym;
    647  1.1  christos     yystate = *yystack.s_mark;
    648  1.1  christos     yystack.l_mark -= yym;
    649  1.1  christos     yym = yylhs[yyn];
    650  1.1  christos     if (yystate == 0 && yym == 0)
    651  1.1  christos     {
    652  1.1  christos #if YYDEBUG
    653  1.1  christos         if (yydebug)
    654  1.1  christos             printf("%sdebug: after reduction, shifting from state 0 to\
    655  1.1  christos  state %d\n", YYPREFIX, YYFINAL);
    656  1.1  christos #endif
    657  1.1  christos         yystate = YYFINAL;
    658  1.1  christos         *++yystack.s_mark = YYFINAL;
    659  1.1  christos         *++yystack.l_mark = yyval;
    660  1.1  christos         if (yychar < 0)
    661  1.1  christos         {
    662  1.2  christos             yychar = YYLEX;
    663  1.2  christos             if (yychar < 0) yychar = YYEOF;
    664  1.1  christos #if YYDEBUG
    665  1.1  christos             if (yydebug)
    666  1.1  christos             {
    667  1.2  christos                 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
    668  1.1  christos                 printf("%sdebug: state %d, reading %d (%s)\n",
    669  1.1  christos                         YYPREFIX, YYFINAL, yychar, yys);
    670  1.1  christos             }
    671  1.1  christos #endif
    672  1.1  christos         }
    673  1.1  christos         if (yychar == YYEOF) goto yyaccept;
    674  1.1  christos         goto yyloop;
    675  1.1  christos     }
    676  1.2  christos     if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
    677  1.2  christos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
    678  1.1  christos         yystate = yytable[yyn];
    679  1.1  christos     else
    680  1.1  christos         yystate = yydgoto[yym];
    681  1.1  christos #if YYDEBUG
    682  1.1  christos     if (yydebug)
    683  1.1  christos         printf("%sdebug: after reduction, shifting from state %d \
    684  1.1  christos to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
    685  1.1  christos #endif
    686  1.2  christos     if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
    687  1.1  christos     *++yystack.s_mark = (YYINT) yystate;
    688  1.1  christos     *++yystack.l_mark = yyval;
    689  1.1  christos     goto yyloop;
    690  1.1  christos 
    691  1.1  christos yyoverflow:
    692  1.1  christos     YYERROR_CALL("yacc stack overflow");
    693  1.1  christos 
    694  1.1  christos yyabort:
    695  1.1  christos     yyfreestack(&yystack);
    696  1.1  christos     return (1);
    697  1.1  christos 
    698  1.1  christos yyaccept:
    699  1.1  christos     yyfreestack(&yystack);
    700  1.1  christos     return (0);
    701  1.1  christos }
    702