1 /* $NetBSD: ok_syntax1.y,v 1.1.1.1 2015/01/03 22:58:23 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 %token STR1
"\x7f\177\\\n"
61 %left UMINUS
/* supplies precedence for unary minus */
63 %%
/* beginning of rules section */
72 { printf
("%d\n",$
<ival
>1);}
74 { regs
[$
<ival
>1] = $
<ival
>3; }
78 { $
<ival
>$
= $
<ival
>2; }
80 { $
<ival
>$
= $
<ival
>1 + $
<ival
>3; }
82 { $
<ival
>$
= $
<ival
>1 - $
<ival
>3; }
84 { $
<ival
>$
= $
<ival
>1 * $
<ival
>3; }
86 { $
<ival
>$
= $
<ival
>1 / $
<ival
>3; }
88 { $
<ival
>$
= $
<ival
>1 % $
<ival
>3; }
90 { $
<ival
>$
= $
<ival
>1 & $
<ival
>3; }
92 { $
<ival
>$
= $
<ival
>1 | $
<ival
>3; }
93 |
'-' expr %prec UMINUS
94 { $
<ival
>$
= - $
<ival
>2; }
96 { $
<ival
>$
= regs
[$
<ival
>1]; }
101 { $
<ival
>$
= $
<ival
>1; (*base
) = ($
<ival
>1==0) ?
8 : 10; }
103 { $
<ival
>$
= (*base
) * $
<ival
>1 + $
<ival
>2; }
106 %%
/* start of programs */
109 extern
int YYLEX_DECL
();
118 while
(!feof
(stdin
)) {
119 yyparse(regs
, &base
);
124 #define UNUSED(x) ((void)(x))
129 UNUSED
(regs
); /* %parse-param regs is not actually used here */
130 UNUSED
(base
); /* %parse-param base is not actually used here */
131 fprintf
(stderr
, "%s\n", s
);
137 /* lexical analysis routine */
138 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
139 /* return DIGIT for a digit, yylval = 0 through 9 */
140 /* all other characters are returned immediately */
144 while
( (c
=getchar
()) == ' ' ) { /* skip blanks */ }
146 /* c is now nonblank */
149 yylval->ival
= (c
- 'a');
153 yylval->ival
= (c
- '0') %
(*base
);