1 /* $NetBSD: calc3.y,v 1.1.1.4 2013/04/06 14:45:28 christos Exp $ */
5 %parse
-param
{ int regs
[26] }
6 %parse
-param
{ int *base
}
8 %lex
-param
{ int *base
}
16 #define YYLEX_PARAM base
17 #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
18 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
20 static void YYERROR_DECL
();
33 %left UMINUS
/* supplies precedence for unary minus */
35 %%
/* beginning of rules section */
65 |
'-' expr %prec UMINUS
73 { $$
= $1; (*base
) = ($1==0) ?
8 : 10; }
75 { $$
= (*base
) * $1 + $2; }
78 %%
/* start of programs */
81 extern
int YYLEX_DECL
();
99 fprintf
(stderr
, "%s\n", s
);
105 /* lexical analysis routine */
106 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
107 /* return DIGIT for a digit, yylval = 0 through 9 */
108 /* all other characters are returned immediately */
112 while
( (c
=getchar
()) == ' ' ) { /* skip blanks */ }
114 /* c is now nonblank */
121 *yylval = (c
- '0') %
(*base
);