tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / flex / dist / examples / manual / expr.y
blob06e6457908fe843546f418f851b2b0862a7d3c57
1 /* $NetBSD: expr.y,v 1.1.1.1 2009/10/26 00:28:33 christos Exp $ */
3 /*
4 * expr.y : A simple yacc expression parser
5 * Based on the Bison manual example.
6 */
8 %{
9 #include <stdio.h>
10 #include <math.h>
14 %union {
15 float val;
18 %token NUMBER
19 %token PLUS MINUS MULT DIV EXPON
20 %token EOL
21 %token LB RB
23 %left MINUS PLUS
24 %left MULT DIV
25 %right EXPON
27 %type <val> exp NUMBER
30 input :
31 | input line
34 line : EOL
35 | exp EOL { printf("%g\n",$1);}
37 exp : NUMBER { $$ = $1; }
38 | exp PLUS exp { $$ = $1 + $3; }
39 | exp MINUS exp { $$ = $1 - $3; }
40 | exp MULT exp { $$ = $1 * $3; }
41 | exp DIV exp { $$ = $1 / $3; }
42 | MINUS exp %prec MINUS { $$ = -$2; }
43 | exp EXPON exp { $$ = pow($1,$3);}
44 | LB exp RB { $$ = $2; }
49 yyerror(char *message)
51 printf("%s\n",message);
54 int main(int argc, char *argv[])
56 yyparse();
57 return(0);