1*9db11b62Schristos /*	$NetBSD: calc3.tab.c,v 1.5 2021/02/20 22:57:57 christos Exp $	*/
21f806d53Schristos 
363eba854Schristos /* original parser id follows */
463eba854Schristos /* yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93" */
563eba854Schristos /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
663eba854Schristos 
763eba854Schristos #define YYBYACC 1
8*9db11b62Schristos #define YYMAJOR 2
9*9db11b62Schristos #define YYMINOR 0
1063eba854Schristos #define YYCHECK "yyyymmdd"
1163eba854Schristos 
1263eba854Schristos #define YYEMPTY        (-1)
1363eba854Schristos #define yyclearin      (yychar = YYEMPTY)
1463eba854Schristos #define yyerrok        (yyerrflag = 0)
1563eba854Schristos #define YYRECOVERING() (yyerrflag != 0)
1663eba854Schristos #define YYENOMEM       (-2)
1763eba854Schristos #define YYEOF          0
1863eba854Schristos 
1963eba854Schristos #ifndef yyparse
2063eba854Schristos #define yyparse    calc3_parse
2163eba854Schristos #endif /* yyparse */
2263eba854Schristos 
2363eba854Schristos #ifndef yylex
2463eba854Schristos #define yylex      calc3_lex
2563eba854Schristos #endif /* yylex */
2663eba854Schristos 
2763eba854Schristos #ifndef yyerror
2863eba854Schristos #define yyerror    calc3_error
2963eba854Schristos #endif /* yyerror */
3063eba854Schristos 
3163eba854Schristos #ifndef yychar
3263eba854Schristos #define yychar     calc3_char
3363eba854Schristos #endif /* yychar */
3463eba854Schristos 
3563eba854Schristos #ifndef yyval
3663eba854Schristos #define yyval      calc3_val
3763eba854Schristos #endif /* yyval */
3863eba854Schristos 
3963eba854Schristos #ifndef yylval
4063eba854Schristos #define yylval     calc3_lval
4163eba854Schristos #endif /* yylval */
4263eba854Schristos 
4363eba854Schristos #ifndef yydebug
4463eba854Schristos #define yydebug    calc3_debug
4563eba854Schristos #endif /* yydebug */
4663eba854Schristos 
4763eba854Schristos #ifndef yynerrs
4863eba854Schristos #define yynerrs    calc3_nerrs
4963eba854Schristos #endif /* yynerrs */
5063eba854Schristos 
5163eba854Schristos #ifndef yyerrflag
5263eba854Schristos #define yyerrflag  calc3_errflag
5363eba854Schristos #endif /* yyerrflag */
5463eba854Schristos 
5563eba854Schristos #ifndef yylhs
5663eba854Schristos #define yylhs      calc3_lhs
5763eba854Schristos #endif /* yylhs */
5863eba854Schristos 
5963eba854Schristos #ifndef yylen
6063eba854Schristos #define yylen      calc3_len
6163eba854Schristos #endif /* yylen */
6263eba854Schristos 
6363eba854Schristos #ifndef yydefred
6463eba854Schristos #define yydefred   calc3_defred
6563eba854Schristos #endif /* yydefred */
6663eba854Schristos 
6763eba854Schristos #ifndef yydgoto
6863eba854Schristos #define yydgoto    calc3_dgoto
6963eba854Schristos #endif /* yydgoto */
7063eba854Schristos 
7163eba854Schristos #ifndef yysindex
7263eba854Schristos #define yysindex   calc3_sindex
7363eba854Schristos #endif /* yysindex */
7463eba854Schristos 
7563eba854Schristos #ifndef yyrindex
7663eba854Schristos #define yyrindex   calc3_rindex
7763eba854Schristos #endif /* yyrindex */
7863eba854Schristos 
7963eba854Schristos #ifndef yygindex
8063eba854Schristos #define yygindex   calc3_gindex
8163eba854Schristos #endif /* yygindex */
8263eba854Schristos 
8363eba854Schristos #ifndef yytable
8463eba854Schristos #define yytable    calc3_table
8563eba854Schristos #endif /* yytable */
8663eba854Schristos 
8763eba854Schristos #ifndef yycheck
8863eba854Schristos #define yycheck    calc3_check
8963eba854Schristos #endif /* yycheck */
9063eba854Schristos 
9163eba854Schristos #ifndef yyname
9263eba854Schristos #define yyname     calc3_name
9363eba854Schristos #endif /* yyname */
9463eba854Schristos 
9563eba854Schristos #ifndef yyrule
9663eba854Schristos #define yyrule     calc3_rule
9763eba854Schristos #endif /* yyrule */
9863eba854Schristos #define YYPREFIX "calc3_"
9963eba854Schristos 
10063eba854Schristos #define YYPURE 1
10163eba854Schristos 
10263eba854Schristos #line 9 "calc3.y"
10363eba854Schristos # include <stdio.h>
10463eba854Schristos # include <ctype.h>
10563eba854Schristos 
10663eba854Schristos #ifdef YYBISON
10763eba854Schristos #define YYSTYPE int
10863eba854Schristos #define YYLEX_PARAM base
10963eba854Schristos #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
11063eba854Schristos #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
11163eba854Schristos int YYLEX_DECL();
11263eba854Schristos static void YYERROR_DECL();
11363eba854Schristos #endif
11463eba854Schristos 
11563eba854Schristos #line 114 "calc3.tab.c"
11663eba854Schristos 
11763eba854Schristos #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
11863eba854Schristos /* Default: YYSTYPE is the semantic value type. */
11963eba854Schristos typedef int YYSTYPE;
12063eba854Schristos # define YYSTYPE_IS_DECLARED 1
12163eba854Schristos #endif
12263eba854Schristos 
12363eba854Schristos /* compatibility with bison */
12463eba854Schristos #ifdef YYPARSE_PARAM
12563eba854Schristos /* compatibility with FreeBSD */
12663eba854Schristos # ifdef YYPARSE_PARAM_TYPE
12763eba854Schristos #  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
12863eba854Schristos # else
12963eba854Schristos #  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
13063eba854Schristos # endif
13163eba854Schristos #else
13263eba854Schristos # define YYPARSE_DECL() yyparse(int regs[26], int *base)
13363eba854Schristos #endif
13463eba854Schristos 
13563eba854Schristos /* Parameters sent to lex. */
13663eba854Schristos #ifdef YYLEX_PARAM
13763eba854Schristos # ifdef YYLEX_PARAM_TYPE
13863eba854Schristos #  define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
13963eba854Schristos # else
14063eba854Schristos #  define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
14163eba854Schristos # endif
14263eba854Schristos # define YYLEX yylex(&yylval, YYLEX_PARAM)
14363eba854Schristos #else
14463eba854Schristos # define YYLEX_DECL() yylex(YYSTYPE *yylval, int *base)
14563eba854Schristos # define YYLEX yylex(&yylval, base)
14663eba854Schristos #endif
14763eba854Schristos 
14863eba854Schristos /* Parameters sent to yyerror. */
14963eba854Schristos #ifndef YYERROR_DECL
15063eba854Schristos #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
15163eba854Schristos #endif
15263eba854Schristos #ifndef YYERROR_CALL
15363eba854Schristos #define YYERROR_CALL(msg) yyerror(regs, base, msg)
15463eba854Schristos #endif
15563eba854Schristos 
15663eba854Schristos extern int YYPARSE_DECL();
15763eba854Schristos 
15863eba854Schristos #define DIGIT 257
15963eba854Schristos #define LETTER 258
16063eba854Schristos #define UMINUS 259
16163eba854Schristos #define YYERRCODE 256
16263eba854Schristos typedef short YYINT;
16363eba854Schristos static const YYINT calc3_lhs[] = {                       -1,
16463eba854Schristos     0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
16563eba854Schristos     2,    2,    2,    2,    2,    2,    3,    3,
16663eba854Schristos };
16763eba854Schristos static const YYINT calc3_len[] = {                        2,
16863eba854Schristos     0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
16963eba854Schristos     3,    3,    3,    2,    1,    1,    1,    2,
17063eba854Schristos };
17163eba854Schristos static const YYINT calc3_defred[] = {                     1,
17263eba854Schristos     0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
17363eba854Schristos     0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
17463eba854Schristos     0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
17563eba854Schristos    10,   11,
17663eba854Schristos };
17763eba854Schristos static const YYINT calc3_dgoto[] = {                      1,
17863eba854Schristos     7,    8,    9,
17963eba854Schristos };
18063eba854Schristos static const YYINT calc3_sindex[] = {                     0,
18163eba854Schristos   -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
18263eba854Schristos   -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
18363eba854Schristos   -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
18463eba854Schristos     0,    0,
18563eba854Schristos };
18663eba854Schristos static const YYINT calc3_rindex[] = {                     0,
18763eba854Schristos     0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
18863eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
18963eba854Schristos     0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
19063eba854Schristos     0,    0,
19163eba854Schristos };
19263eba854Schristos static const YYINT calc3_gindex[] = {                     0,
19363eba854Schristos     0,   65,    0,
19463eba854Schristos };
19563eba854Schristos #define YYTABLESIZE 220
19663eba854Schristos static const YYINT calc3_table[] = {                      6,
19763eba854Schristos    16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
19863eba854Schristos    15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
19963eba854Schristos     0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
20063eba854Schristos     0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
20163eba854Schristos     0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
20263eba854Schristos     8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
20363eba854Schristos     0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
20463eba854Schristos    14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
20563eba854Schristos    26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
20663eba854Schristos     0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
20763eba854Schristos     0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
20863eba854Schristos     0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
20963eba854Schristos     0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
21063eba854Schristos     0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
21163eba854Schristos     0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
21263eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21363eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21463eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21563eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21663eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21763eba854Schristos     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
21863eba854Schristos     0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
21963eba854Schristos };
22063eba854Schristos static const YYINT calc3_check[] = {                     40,
22163eba854Schristos    10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
22263eba854Schristos    10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
22363eba854Schristos    -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
22463eba854Schristos    -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
22563eba854Schristos    -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
22663eba854Schristos    38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
22763eba854Schristos    -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
22863eba854Schristos     6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
22963eba854Schristos    16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
23063eba854Schristos    -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
23163eba854Schristos    -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
23263eba854Schristos    -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
23363eba854Schristos    -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
23463eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
23563eba854Schristos    -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
23663eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
23763eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
23863eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
23963eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
24063eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
24163eba854Schristos    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
24263eba854Schristos    -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
24363eba854Schristos };
24463eba854Schristos #define YYFINAL 1
24563eba854Schristos #ifndef YYDEBUG
24663eba854Schristos #define YYDEBUG 0
24763eba854Schristos #endif
24863eba854Schristos #define YYMAXTOKEN 259
24963eba854Schristos #define YYUNDFTOKEN 265
25063eba854Schristos #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
25163eba854Schristos #if YYDEBUG
25263eba854Schristos static const char *const calc3_name[] = {
25363eba854Schristos 
25463eba854Schristos "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,
25563eba854Schristos 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
25663eba854Schristos 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,
25763eba854Schristos 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,
25863eba854Schristos 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,
25963eba854Schristos 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,
26063eba854Schristos 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,
26163eba854Schristos 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",0,0,0,0,0,"illegal-symbol",
26263eba854Schristos };
26363eba854Schristos static const char *const calc3_rule[] = {
26463eba854Schristos "$accept : list",
26563eba854Schristos "list :",
26663eba854Schristos "list : list stat '\\n'",
26763eba854Schristos "list : list error '\\n'",
26863eba854Schristos "stat : expr",
26963eba854Schristos "stat : LETTER '=' expr",
27063eba854Schristos "expr : '(' expr ')'",
27163eba854Schristos "expr : expr '+' expr",
27263eba854Schristos "expr : expr '-' expr",
27363eba854Schristos "expr : expr '*' expr",
27463eba854Schristos "expr : expr '/' expr",
27563eba854Schristos "expr : expr '%' expr",
27663eba854Schristos "expr : expr '&' expr",
27763eba854Schristos "expr : expr '|' expr",
27863eba854Schristos "expr : '-' expr",
27963eba854Schristos "expr : LETTER",
28063eba854Schristos "expr : number",
28163eba854Schristos "number : DIGIT",
28263eba854Schristos "number : number DIGIT",
28363eba854Schristos 
28463eba854Schristos };
28563eba854Schristos #endif
28663eba854Schristos 
28703120b04Schristos #if YYDEBUG
28863eba854Schristos int      yydebug;
28903120b04Schristos #endif
29063eba854Schristos 
29163eba854Schristos /* define the initial stack-sizes */
29263eba854Schristos #ifdef YYSTACKSIZE
29363eba854Schristos #undef YYMAXDEPTH
29463eba854Schristos #define YYMAXDEPTH  YYSTACKSIZE
29563eba854Schristos #else
29663eba854Schristos #ifdef YYMAXDEPTH
29763eba854Schristos #define YYSTACKSIZE YYMAXDEPTH
29863eba854Schristos #else
29963eba854Schristos #define YYSTACKSIZE 10000
30063eba854Schristos #define YYMAXDEPTH  10000
30163eba854Schristos #endif
30263eba854Schristos #endif
30363eba854Schristos 
30463eba854Schristos #define YYINITSTACKSIZE 200
30563eba854Schristos 
30663eba854Schristos typedef struct {
30763eba854Schristos     unsigned stacksize;
30863eba854Schristos     YYINT    *s_base;
30963eba854Schristos     YYINT    *s_mark;
31063eba854Schristos     YYINT    *s_last;
31163eba854Schristos     YYSTYPE  *l_base;
31263eba854Schristos     YYSTYPE  *l_mark;
31363eba854Schristos } YYSTACKDATA;
31463eba854Schristos #line 76 "calc3.y"
31563eba854Schristos  /* start of programs */
31663eba854Schristos 
31763eba854Schristos #ifdef YYBYACC
31863eba854Schristos extern int YYLEX_DECL();
31963eba854Schristos #endif
32063eba854Schristos 
32163eba854Schristos int
main(void)32263eba854Schristos main (void)
32363eba854Schristos {
32463eba854Schristos     int regs[26];
32563eba854Schristos     int base = 10;
32663eba854Schristos 
32763eba854Schristos     while(!feof(stdin)) {
32863eba854Schristos 	yyparse(regs, &base);
32963eba854Schristos     }
33063eba854Schristos     return 0;
33163eba854Schristos }
33263eba854Schristos 
33363eba854Schristos #define UNUSED(x) ((void)(x))
33463eba854Schristos 
33563eba854Schristos static void
YYERROR_DECL()33663eba854Schristos YYERROR_DECL()
33763eba854Schristos {
33863eba854Schristos     UNUSED(regs); /* %parse-param regs is not actually used here */
33963eba854Schristos     UNUSED(base); /* %parse-param base is not actually used here */
34063eba854Schristos     fprintf(stderr, "%s\n", s);
34163eba854Schristos }
34263eba854Schristos 
34363eba854Schristos int
YYLEX_DECL()34463eba854Schristos YYLEX_DECL()
34563eba854Schristos {
34663eba854Schristos 	/* lexical analysis routine */
34763eba854Schristos 	/* returns LETTER for a lower case letter, yylval = 0 through 25 */
34863eba854Schristos 	/* return DIGIT for a digit, yylval = 0 through 9 */
34963eba854Schristos 	/* all other characters are returned immediately */
35063eba854Schristos 
35163eba854Schristos     int c;
35263eba854Schristos 
35363eba854Schristos     while( (c=getchar()) == ' ' )   { /* skip blanks */ }
35463eba854Schristos 
35563eba854Schristos     /* c is now nonblank */
35663eba854Schristos 
35763eba854Schristos     if( islower( c )) {
35863eba854Schristos 	*yylval = (c - 'a');
35963eba854Schristos 	return ( LETTER );
36063eba854Schristos     }
36163eba854Schristos     if( isdigit( c )) {
36263eba854Schristos 	*yylval = (c - '0') % (*base);
36363eba854Schristos 	return ( DIGIT );
36463eba854Schristos     }
36563eba854Schristos     return( c );
36663eba854Schristos }
36703120b04Schristos #line 366 "calc3.tab.c"
36863eba854Schristos 
36963eba854Schristos #if YYDEBUG
37063eba854Schristos #include <stdio.h>	/* needed for printf */
37163eba854Schristos #endif
37263eba854Schristos 
37363eba854Schristos #include <stdlib.h>	/* needed for malloc, etc */
37463eba854Schristos #include <string.h>	/* needed for memset */
37563eba854Schristos 
37663eba854Schristos /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(YYSTACKDATA * data)37763eba854Schristos static int yygrowstack(YYSTACKDATA *data)
37863eba854Schristos {
37963eba854Schristos     int i;
38063eba854Schristos     unsigned newsize;
38163eba854Schristos     YYINT *newss;
38263eba854Schristos     YYSTYPE *newvs;
38363eba854Schristos 
38463eba854Schristos     if ((newsize = data->stacksize) == 0)
38563eba854Schristos         newsize = YYINITSTACKSIZE;
38663eba854Schristos     else if (newsize >= YYMAXDEPTH)
38763eba854Schristos         return YYENOMEM;
38863eba854Schristos     else if ((newsize *= 2) > YYMAXDEPTH)
38963eba854Schristos         newsize = YYMAXDEPTH;
39063eba854Schristos 
39163eba854Schristos     i = (int) (data->s_mark - data->s_base);
39263eba854Schristos     newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
39363eba854Schristos     if (newss == 0)
39463eba854Schristos         return YYENOMEM;
39563eba854Schristos 
39663eba854Schristos     data->s_base = newss;
39763eba854Schristos     data->s_mark = newss + i;
39863eba854Schristos 
39963eba854Schristos     newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
40063eba854Schristos     if (newvs == 0)
40163eba854Schristos         return YYENOMEM;
40263eba854Schristos 
40363eba854Schristos     data->l_base = newvs;
40463eba854Schristos     data->l_mark = newvs + i;
40563eba854Schristos 
40663eba854Schristos     data->stacksize = newsize;
40763eba854Schristos     data->s_last = data->s_base + newsize - 1;
40863eba854Schristos     return 0;
40963eba854Schristos }
41063eba854Schristos 
41163eba854Schristos #if YYPURE || defined(YY_NO_LEAKS)
yyfreestack(YYSTACKDATA * data)41263eba854Schristos static void yyfreestack(YYSTACKDATA *data)
41363eba854Schristos {
41463eba854Schristos     free(data->s_base);
41563eba854Schristos     free(data->l_base);
41663eba854Schristos     memset(data, 0, sizeof(*data));
41763eba854Schristos }
41863eba854Schristos #else
41963eba854Schristos #define yyfreestack(data) /* nothing */
42063eba854Schristos #endif
42163eba854Schristos 
42263eba854Schristos #define YYABORT  goto yyabort
42363eba854Schristos #define YYREJECT goto yyabort
42463eba854Schristos #define YYACCEPT goto yyaccept
42563eba854Schristos #define YYERROR  goto yyerrlab
42663eba854Schristos 
42763eba854Schristos int
YYPARSE_DECL()42863eba854Schristos YYPARSE_DECL()
42963eba854Schristos {
43063eba854Schristos     int      yyerrflag;
43163eba854Schristos     int      yychar;
43263eba854Schristos     YYSTYPE  yyval;
43363eba854Schristos     YYSTYPE  yylval;
43403120b04Schristos     int      yynerrs;
43563eba854Schristos 
43663eba854Schristos     /* variables for the parser stack */
43763eba854Schristos     YYSTACKDATA yystack;
43863eba854Schristos     int yym, yyn, yystate;
43963eba854Schristos #if YYDEBUG
44063eba854Schristos     const char *yys;
44163eba854Schristos 
44263eba854Schristos     if ((yys = getenv("YYDEBUG")) != 0)
44363eba854Schristos     {
44463eba854Schristos         yyn = *yys;
44563eba854Schristos         if (yyn >= '0' && yyn <= '9')
44663eba854Schristos             yydebug = yyn - '0';
44763eba854Schristos     }
44863eba854Schristos #endif
44963eba854Schristos 
450900f8c6bSchristos     memset(&yyval,  0, sizeof(yyval));
451900f8c6bSchristos     memset(&yylval, 0, sizeof(yylval));
452900f8c6bSchristos 
45365d89d9aSchristos     yym = 0;
45465d89d9aSchristos     yyn = 0;
45563eba854Schristos     yynerrs = 0;
45663eba854Schristos     yyerrflag = 0;
45763eba854Schristos     yychar = YYEMPTY;
45863eba854Schristos     yystate = 0;
45963eba854Schristos 
46063eba854Schristos #if YYPURE
46163eba854Schristos     memset(&yystack, 0, sizeof(yystack));
46263eba854Schristos #endif
46363eba854Schristos 
46463eba854Schristos     if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
46563eba854Schristos     yystack.s_mark = yystack.s_base;
46663eba854Schristos     yystack.l_mark = yystack.l_base;
46763eba854Schristos     yystate = 0;
46863eba854Schristos     *yystack.s_mark = 0;
46963eba854Schristos 
47063eba854Schristos yyloop:
47163eba854Schristos     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
47263eba854Schristos     if (yychar < 0)
47363eba854Schristos     {
47465d89d9aSchristos         yychar = YYLEX;
47565d89d9aSchristos         if (yychar < 0) yychar = YYEOF;
47663eba854Schristos #if YYDEBUG
47763eba854Schristos         if (yydebug)
47863eba854Schristos         {
47965d89d9aSchristos             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
48063eba854Schristos             printf("%sdebug: state %d, reading %d (%s)\n",
48163eba854Schristos                     YYPREFIX, yystate, yychar, yys);
48263eba854Schristos         }
48363eba854Schristos #endif
48463eba854Schristos     }
48565d89d9aSchristos     if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
48665d89d9aSchristos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
48763eba854Schristos     {
48863eba854Schristos #if YYDEBUG
48963eba854Schristos         if (yydebug)
49063eba854Schristos             printf("%sdebug: state %d, shifting to state %d\n",
49163eba854Schristos                     YYPREFIX, yystate, yytable[yyn]);
49263eba854Schristos #endif
49365d89d9aSchristos         if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
49463eba854Schristos         yystate = yytable[yyn];
49563eba854Schristos         *++yystack.s_mark = yytable[yyn];
49663eba854Schristos         *++yystack.l_mark = yylval;
49763eba854Schristos         yychar = YYEMPTY;
49863eba854Schristos         if (yyerrflag > 0)  --yyerrflag;
49963eba854Schristos         goto yyloop;
50063eba854Schristos     }
50165d89d9aSchristos     if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
50265d89d9aSchristos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
50363eba854Schristos     {
50463eba854Schristos         yyn = yytable[yyn];
50563eba854Schristos         goto yyreduce;
50663eba854Schristos     }
50765d89d9aSchristos     if (yyerrflag != 0) goto yyinrecovery;
50863eba854Schristos 
50963eba854Schristos     YYERROR_CALL("syntax error");
51063eba854Schristos 
51165d89d9aSchristos     goto yyerrlab; /* redundant goto avoids 'unused label' warning */
51263eba854Schristos yyerrlab:
51363eba854Schristos     ++yynerrs;
51463eba854Schristos 
51563eba854Schristos yyinrecovery:
51663eba854Schristos     if (yyerrflag < 3)
51763eba854Schristos     {
51863eba854Schristos         yyerrflag = 3;
51963eba854Schristos         for (;;)
52063eba854Schristos         {
52165d89d9aSchristos             if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
52265d89d9aSchristos                     yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
52363eba854Schristos             {
52463eba854Schristos #if YYDEBUG
52563eba854Schristos                 if (yydebug)
52663eba854Schristos                     printf("%sdebug: state %d, error recovery shifting\
52763eba854Schristos  to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
52863eba854Schristos #endif
52965d89d9aSchristos                 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
53063eba854Schristos                 yystate = yytable[yyn];
53163eba854Schristos                 *++yystack.s_mark = yytable[yyn];
53263eba854Schristos                 *++yystack.l_mark = yylval;
53363eba854Schristos                 goto yyloop;
53463eba854Schristos             }
53563eba854Schristos             else
53663eba854Schristos             {
53763eba854Schristos #if YYDEBUG
53863eba854Schristos                 if (yydebug)
53963eba854Schristos                     printf("%sdebug: error recovery discarding state %d\n",
54063eba854Schristos                             YYPREFIX, *yystack.s_mark);
54163eba854Schristos #endif
54263eba854Schristos                 if (yystack.s_mark <= yystack.s_base) goto yyabort;
54363eba854Schristos                 --yystack.s_mark;
54463eba854Schristos                 --yystack.l_mark;
54563eba854Schristos             }
54663eba854Schristos         }
54763eba854Schristos     }
54863eba854Schristos     else
54963eba854Schristos     {
55063eba854Schristos         if (yychar == YYEOF) goto yyabort;
55163eba854Schristos #if YYDEBUG
55263eba854Schristos         if (yydebug)
55363eba854Schristos         {
55465d89d9aSchristos             if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
55563eba854Schristos             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
55663eba854Schristos                     YYPREFIX, yystate, yychar, yys);
55763eba854Schristos         }
55863eba854Schristos #endif
55963eba854Schristos         yychar = YYEMPTY;
56063eba854Schristos         goto yyloop;
56163eba854Schristos     }
56263eba854Schristos 
56363eba854Schristos yyreduce:
56463eba854Schristos #if YYDEBUG
56563eba854Schristos     if (yydebug)
56663eba854Schristos         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
56763eba854Schristos                 YYPREFIX, yystate, yyn, yyrule[yyn]);
56863eba854Schristos #endif
56963eba854Schristos     yym = yylen[yyn];
57065d89d9aSchristos     if (yym > 0)
57163eba854Schristos         yyval = yystack.l_mark[1-yym];
57263eba854Schristos     else
57363eba854Schristos         memset(&yyval, 0, sizeof yyval);
57465d89d9aSchristos 
57563eba854Schristos     switch (yyn)
57663eba854Schristos     {
57763eba854Schristos case 3:
57863eba854Schristos #line 38 "calc3.y"
57963eba854Schristos 	{  yyerrok ; }
58063eba854Schristos break;
58163eba854Schristos case 4:
58263eba854Schristos #line 42 "calc3.y"
58363eba854Schristos 	{  printf("%d\n",yystack.l_mark[0]);}
58463eba854Schristos break;
58563eba854Schristos case 5:
58663eba854Schristos #line 44 "calc3.y"
58763eba854Schristos 	{  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
58863eba854Schristos break;
58963eba854Schristos case 6:
59063eba854Schristos #line 48 "calc3.y"
59163eba854Schristos 	{  yyval = yystack.l_mark[-1]; }
59263eba854Schristos break;
59363eba854Schristos case 7:
59463eba854Schristos #line 50 "calc3.y"
59563eba854Schristos 	{  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
59663eba854Schristos break;
59763eba854Schristos case 8:
59863eba854Schristos #line 52 "calc3.y"
59963eba854Schristos 	{  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
60063eba854Schristos break;
60163eba854Schristos case 9:
60263eba854Schristos #line 54 "calc3.y"
60363eba854Schristos 	{  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
60463eba854Schristos break;
60563eba854Schristos case 10:
60663eba854Schristos #line 56 "calc3.y"
60763eba854Schristos 	{  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
60863eba854Schristos break;
60963eba854Schristos case 11:
61063eba854Schristos #line 58 "calc3.y"
61163eba854Schristos 	{  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
61263eba854Schristos break;
61363eba854Schristos case 12:
61463eba854Schristos #line 60 "calc3.y"
61563eba854Schristos 	{  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
61663eba854Schristos break;
61763eba854Schristos case 13:
61863eba854Schristos #line 62 "calc3.y"
61963eba854Schristos 	{  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
62063eba854Schristos break;
62163eba854Schristos case 14:
62263eba854Schristos #line 64 "calc3.y"
62363eba854Schristos 	{  yyval = - yystack.l_mark[0]; }
62463eba854Schristos break;
62563eba854Schristos case 15:
62663eba854Schristos #line 66 "calc3.y"
62763eba854Schristos 	{  yyval = regs[yystack.l_mark[0]]; }
62863eba854Schristos break;
62963eba854Schristos case 17:
63063eba854Schristos #line 71 "calc3.y"
63163eba854Schristos 	{  yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
63263eba854Schristos break;
63363eba854Schristos case 18:
63463eba854Schristos #line 73 "calc3.y"
63563eba854Schristos 	{  yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
63663eba854Schristos break;
63703120b04Schristos #line 636 "calc3.tab.c"
63863eba854Schristos     }
63963eba854Schristos     yystack.s_mark -= yym;
64063eba854Schristos     yystate = *yystack.s_mark;
64163eba854Schristos     yystack.l_mark -= yym;
64263eba854Schristos     yym = yylhs[yyn];
64363eba854Schristos     if (yystate == 0 && yym == 0)
64463eba854Schristos     {
64563eba854Schristos #if YYDEBUG
64663eba854Schristos         if (yydebug)
64763eba854Schristos             printf("%sdebug: after reduction, shifting from state 0 to\
64863eba854Schristos  state %d\n", YYPREFIX, YYFINAL);
64963eba854Schristos #endif
65063eba854Schristos         yystate = YYFINAL;
65163eba854Schristos         *++yystack.s_mark = YYFINAL;
65263eba854Schristos         *++yystack.l_mark = yyval;
65363eba854Schristos         if (yychar < 0)
65463eba854Schristos         {
65565d89d9aSchristos             yychar = YYLEX;
65665d89d9aSchristos             if (yychar < 0) yychar = YYEOF;
65763eba854Schristos #if YYDEBUG
65863eba854Schristos             if (yydebug)
65963eba854Schristos             {
66065d89d9aSchristos                 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
66163eba854Schristos                 printf("%sdebug: state %d, reading %d (%s)\n",
66263eba854Schristos                         YYPREFIX, YYFINAL, yychar, yys);
66363eba854Schristos             }
66463eba854Schristos #endif
66563eba854Schristos         }
66663eba854Schristos         if (yychar == YYEOF) goto yyaccept;
66763eba854Schristos         goto yyloop;
66863eba854Schristos     }
66965d89d9aSchristos     if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
67065d89d9aSchristos             yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
67163eba854Schristos         yystate = yytable[yyn];
67263eba854Schristos     else
67363eba854Schristos         yystate = yydgoto[yym];
67463eba854Schristos #if YYDEBUG
67563eba854Schristos     if (yydebug)
67663eba854Schristos         printf("%sdebug: after reduction, shifting from state %d \
67763eba854Schristos to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
67863eba854Schristos #endif
67965d89d9aSchristos     if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
68063eba854Schristos     *++yystack.s_mark = (YYINT) yystate;
68163eba854Schristos     *++yystack.l_mark = yyval;
68263eba854Schristos     goto yyloop;
68363eba854Schristos 
68463eba854Schristos yyoverflow:
68563eba854Schristos     YYERROR_CALL("yacc stack overflow");
68663eba854Schristos 
68763eba854Schristos yyabort:
68863eba854Schristos     yyfreestack(&yystack);
68963eba854Schristos     return (1);
69063eba854Schristos 
69163eba854Schristos yyaccept:
69263eba854Schristos     yyfreestack(&yystack);
69363eba854Schristos     return (0);
69463eba854Schristos }
695