Debian Codegraph @

documentation/manual/demos/rpn/parser/grammar

raw
1 //DECL
2 %baseclass-preinclude cmath
3
4 %token NUM
5 %stype double
6
7 //=
8 %%
9 //RULES
10 input:
11 // empty
12 |
13 input line
14 ;
15
16 line:
17 '\n'
18 |
19 exp '\n'
20 {
21 std::cout << "\t" << $1 << std::endl;
22 }
23 ;
24
25 exp:
26 NUM
27 |
28 exp exp '+'
29 {
30 $$ = $1 + $2;
31 }
32 |
33 exp exp '-'
34 {
35 $$ = $1 - $2;
36 }
37 |
38 exp exp '*'
39 {
40 $$ = $1 * $2;
41 }
42 |
43 exp exp '/'
44 {
45 $$ = $1 / $2;
46 }
47 |
48 // Exponentiation:
49 exp exp '^'
50 {
51 $$ = pow($1, $2);
52 }
53 |
54 // Unary minus:
55 exp 'n'
56 {
57 $$ = -$1;
58 }
59 ;
60 //=