Remove building with NOCRYPTO option
[minix3.git] / external / bsd / byacc / dist / test / calc2.y
blob395248ae35b3ea15c7666fad9c9a4a117642f601
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 }
8 %{
9 # include <stdio.h>
10 # include <ctype.h>
12 #ifdef YYBISON
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)
16 int YYLEX_DECL();
17 static void YYERROR_DECL();
18 #endif
22 %start list
24 %token DIGIT LETTER
26 %left '|'
27 %left '&'
28 %left '+' '-'
29 %left '*' '/' '%'
30 %left UMINUS /* supplies precedence for unary minus */
32 %% /* beginning of rules section */
34 list : /* empty */
35 | list stat '\n'
36 | list error '\n'
37 { yyerrok ; }
40 stat : expr
41 { printf("%d\n",$1);}
42 | LETTER '=' expr
43 { regs[$1] = $3; }
46 expr : '(' expr ')'
47 { $$ = $2; }
48 | expr '+' expr
49 { $$ = $1 + $3; }
50 | expr '-' expr
51 { $$ = $1 - $3; }
52 | expr '*' expr
53 { $$ = $1 * $3; }
54 | expr '/' expr
55 { $$ = $1 / $3; }
56 | expr '%' expr
57 { $$ = $1 % $3; }
58 | expr '&' expr
59 { $$ = $1 & $3; }
60 | expr '|' expr
61 { $$ = $1 | $3; }
62 | '-' expr %prec UMINUS
63 { $$ = - $2; }
64 | LETTER
65 { $$ = regs[$1]; }
66 | number
69 number: DIGIT
70 { $$ = $1; (*base) = ($1==0) ? 8 : 10; }
71 | number DIGIT
72 { $$ = (*base) * $1 + $2; }
75 %% /* start of programs */
77 #ifdef YYBYACC
78 extern int YYLEX_DECL();
79 #endif
81 int
82 main (void)
84 int regs[26];
85 int base = 10;
87 while(!feof(stdin)) {
88 yyparse(regs, &base);
90 return 0;
93 #define UNUSED(x) ((void)(x))
95 static void
96 YYERROR_DECL()
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);
104 YYLEX_DECL()
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 */
111 int c;
113 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
115 /* c is now nonblank */
117 if( islower( c )) {
118 yylval = c - 'a';
119 return ( LETTER );
121 if( isdigit( c )) {
122 yylval = (c - '0') % (*base);
123 return ( DIGIT );
125 return( c );