1 /* $NetBSD: calc2.y,v 1.1.1.5 2015/01/03 22:58:23 christos Exp $ */
3 %parse
-param
{ int regs
[26] }
4 %parse
-param
{ int *base
}
6 %lex
-param
{ int *base
}
13 #define YYLEX_PARAM base
14 #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
15 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
17 static void YYERROR_DECL
();
30 %left UMINUS
/* supplies precedence for unary minus */
32 %%
/* beginning of rules section */
62 |
'-' expr %prec UMINUS
70 { $$
= $1; (*base
) = ($1==0) ?
8 : 10; }
72 { $$
= (*base
) * $1 + $2; }
75 %%
/* start of programs */
78 extern
int YYLEX_DECL
();
93 #define UNUSED(x) ((void)(x))
98 UNUSED
(regs
); /* %parse-param regs is not actually used here */
99 UNUSED
(base
); /* %parse-param base is not actually used here */
100 fprintf
(stderr
, "%s\n", s
);
106 /* lexical analysis routine */
107 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
108 /* return DIGIT for a digit, yylval = 0 through 9 */
109 /* all other characters are returned immediately */
113 while
( (c
=getchar
()) == ' ' ) { /* skip blanks */ }
115 /* c is now nonblank */
122 yylval = (c
- '0') %
(*base
);