Debian Codegraph @

yo/concrete/bisonc++/parser/grammar

raw
1 //DECLARATION
2 %filenames parser
3 %scanner ../scanner/scanner.h
4
5 %union {
6 int i;
7 double d;
8 };
9
10 %token INT DOUBLE
11
12 %type <i> intExpr
13 %type <d> doubleExpr
14
15 %left '+'
16 %left '*'
17 %right UnaryMinus
18 //=
19 %%
20 //RULES
21 lines:
22 lines
23 line
24 |
25 line
26 ;
27
28 line:
29 intExpr
30 '\n'
31 {
32 display($1);
33 }
34 |
35 doubleExpr
36 '\n'
37 {
38 display($1);
39 }
40 |
41 '\n'
42 {
43 done();
44 }
45 |
46 error
47 '\n'
48 {
49 reset();
50 }
51 ;
52
53 intExpr:
54 intExpr '*' intExpr
55 {
56 $$ = exec('*', $1, $3);
57 }
58 |
59 intExpr '+' intExpr
60 {
61 $$ = exec('+', $1, $3);
62 }
63 |
64 '(' intExpr ')'
65 {
66
67 $$ = $2;
68 }
69 |
70 '-' intExpr %prec UnaryMinus
71 {
72 $$ = neg($2);
73 }
74 |
75 INT
76 {
77 $$ = convert<int>();
78 }
79 ;
80
81 doubleExpr:
82 doubleExpr '*' doubleExpr
83 {
84 $$ = exec('*', $1, $3);
85 }
86 |
87 doubleExpr '*' intExpr
88 {
89 $$ = exec('*', $1, d($3));
90 }
91 |
92 intExpr '*' doubleExpr
93 {
94 $$ = exec('*', d($1), $3);
95 }
96 |
97 doubleExpr '+' doubleExpr
98 {
99 $$ = exec('+', $1, $3);
100 }
101 |
102 doubleExpr '+' intExpr
103 {
104 $$ = exec('+', $1, d($3));
105 }
106 |
107 intExpr '+' doubleExpr
108 {
109 $$ = exec('+', d($1), $3);
110 }
111 |
112 '(' doubleExpr ')'
113 {
114 $$ = $2;
115 }
116 |
117 '-' doubleExpr %prec UnaryMinus
118 {
119
120 $$ = neg($2);
121 }
122 |
123 DOUBLE
124 {
125 $$ = convert<double>();
126 }
127 ;
128 //=