tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / quote_calc.y
blob72bbe05720d8cf5df832e838db2a7d36f476828f
1 /* $NetBSD: quote_calc.y,v 1.1.1.1 2013/04/06 14:45:30 christos Exp $ */
3 %{
4 # include <stdio.h>
5 # include <ctype.h>
7 int regs[26];
8 int base;
10 int yylex(void);
11 static void yyerror(const char *s);
15 %start list
17 %token OP_ADD "ADD"
18 %token OP_SUB "SUB"
19 %token OP_MUL "MUL"
20 %token OP_DIV "DIV"
21 %token OP_MOD "MOD"
22 %token OP_AND "AND"
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 OP_ADD expr
49 { $$ = $1 + $3; }
50 | expr OP_SUB expr
51 { $$ = $1 - $3; }
52 | expr OP_MUL expr
53 { $$ = $1 * $3; }
54 | expr OP_DIV expr
55 { $$ = $1 / $3; }
56 | expr OP_MOD expr
57 { $$ = $1 % $3; }
58 | expr OP_AND expr
59 { $$ = $1 & $3; }
60 | expr '|' expr
61 { $$ = $1 | $3; }
62 | OP_SUB 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 int
78 main (void)
80 while(!feof(stdin)) {
81 yyparse();
83 return 0;
86 static void
87 yyerror(const char *s)
89 fprintf(stderr, "%s\n", s);
92 int
93 yylex(void) {
94 /* lexical analysis routine */
95 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
96 /* return DIGIT for a digit, yylval = 0 through 9 */
97 /* all other characters are returned immediately */
99 int c;
101 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
103 /* c is now nonblank */
105 if( islower( c )) {
106 yylval = c - 'a';
107 return ( LETTER );
109 if( isdigit( c )) {
110 yylval = c - '0';
111 return ( DIGIT );
113 return( c );