3 %parse_param { int regs[26] }
4 %parse_param { int *base }
6 %lex_param { int *base }
14 #define YYLEX_PARAM base
15 #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
16 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
18 static void YYERROR_DECL();
31 %token STR1 "\x7f\177\\\n"
59 %left UMINUS /* supplies precedence for unary minus */
61 %% /* beginning of rules section */
70 { printf("%d\n",$<ival>1);}
72 { regs[$<ival>1] = $<ival>3; }
76 { $<ival>$ = $<ival>2; }
78 { $<ival>$ = $<ival>1 + $<ival>3; }
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; }
91 | '-' expr %prec UMINUS
92 { $<ival>$ = - $<ival>2; }
94 { $<ival>$ = regs[$<ival>1]; }
99 { $<ival>$ = $<ival>1; (*base) = ($<ival>1==0) ? 8 : 10; }
101 { $<ival>$ = (*base) * $<ival>1 + $<ival>2; }
104 %% /* start of programs */
107 extern int YYLEX_DECL();
116 while(!feof(stdin)) {
117 yyparse(regs, &base);
122 #define UNUSED(x) ((void)(x))
127 UNUSED(regs); /* %parse-param regs is not actually used here */
128 UNUSED(base); /* %parse-param base is not actually used here */
129 fprintf(stderr, "%s\n", s);
135 /* lexical analysis routine */
136 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
137 /* return DIGIT for a digit, yylval = 0 through 9 */
138 /* all other characters are returned immediately */
142 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
144 /* c is now nonblank */
147 yylval->ival = (c - 'a');
151 yylval->ival = (c - '0') % (*base);