8 static struct tree* tree_malloc(int type);
24 %token <n> KW_PIPE KW_MAIL KW_COPY
25 %token '(' ')' '{' '}' ';'
29 %left <n> EQ NEQ GE LE '<' '>' RE NRE
42 %type <tr> ass_right_p
52 input: /* empty */ { $$ = input_tree = tree_malloc(ST_EMPTY); }
53 | command input { $$ = tree_malloc(ST_BLOCK);
54 $$->pt.block.head = $1;
55 $$->pt.block.tail = $2;
61 command: ';' { $$ = tree_malloc(ST_EMPTY); }
62 | '{' command next '}' {
63 $$ = tree_malloc(ST_BLOCK);
64 $$->pt.block.head = $2;
65 $$->pt.block.tail = $3;
67 | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
69 | ass ';' { $$ = $1; }
70 | arrow ';' { $$ = $1; }
75 next: /* empty */ {$$ = tree_malloc(ST_EMPTY); }
81 cif: KW_IF cond command KW_ELSE command {
82 $$ = tree_malloc(ST_IF);
87 | KW_IF cond command {
88 $$ = tree_malloc(ST_IF);
91 $$->pt.tif.e = tree_malloc(ST_EMPTY);
96 $$ = tree_malloc(ST_COND);
97 $$->pt.cond.left = $2;
98 $$->pt.cond.right = NULL;
100 $$->pt.cond.type = OP_BOOL;
103 $$ = tree_malloc(ST_COND);
104 $$->pt.cond.left = $1;
105 $$->pt.cond.right = $3;
107 $$->pt.cond.type = OP_BOOL;
110 $$ = tree_malloc(ST_COND);
111 $$->pt.cond.left = $1;
112 $$->pt.cond.right = $3;
114 $$->pt.cond.type = OP_BOOL;
117 $$ = tree_malloc(ST_COND);
118 $$->pt.cond.left = $1;
119 $$->pt.cond.right = $3;
121 $$->pt.cond.type = OP_BOOL;
124 | '(' cond ')' { $$ = $2; }
125 | ass_right rop ass_right {
126 $$ = tree_malloc(ST_COND);
127 $$->pt.cond.left = $1;
128 $$->pt.cond.right = $3;
130 $$->pt.cond.type = OP_REL;
133 $$ = tree_malloc(ST_COND);
134 $$->pt.cond.left = $1;
135 $$->pt.cond.type = JUST_BOOL;
150 VAR '=' ass_right_p {
151 $$ = tree_malloc(ST_ASS);
153 $$->pt.ass.left = tree_malloc(ST_LEAF);
154 $$->pt.ass.left->pt.leaf.type = L_VAR;
155 $$->pt.ass.left->pt.leaf.value = $1;
156 $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash);
157 $$->pt.ass.right = $3;
162 $$ = tree_malloc(ST_LEAF);
163 $$->pt.leaf.type = L_VAR;
164 $$->pt.leaf.value = $1;
165 $$->pt.leaf.n = find_var($1, var_hash);
168 $$ = tree_malloc(ST_LEAF);
169 $$->pt.leaf.type = L_CONST;
170 $$->pt.leaf.value = $1;
171 $$->pt.leaf.n = store_const($1);
175 arrow: left ARROW right ass_right {
176 $$ = tree_malloc(ST_ARROW);
178 $$->pt.arrow.left = $1;
179 $$->pt.arrow.right = $3;
181 | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
182 $$ = tree_malloc(ST_ARROW);
183 $$->pt.arrow.s = NULL;
184 $$->pt.arrow.left = K_EMPTY;
185 $$->pt.arrow.right = K_DISCARD;
189 left: /* empty */ { $$ = K_EMPTY;}
190 | KW_COPY { $$ = K_COPY; }
194 right: /* empty */ { $$ = K_EMPTY; }
195 | KW_PIPE { $$ = K_PIPE; }
196 | KW_MAIL { $$ = K_MAIL; }
199 ass_right_p: '(' ass_right ')' {$$ = $2; }
200 | ass_right {$$ = $1; }
204 | ass_right '.' ass_right {
205 $$ = tree_malloc(ST_OP);
208 $$->pt.op.right = $3;
210 | ass_right '+' ass_right {
211 $$ = tree_malloc(ST_OP);
214 $$->pt.op.right = $3;
216 | ass_right '-' ass_right {
217 $$ = tree_malloc(ST_OP);
220 $$->pt.op.right = $3;
222 | ass_right '*' ass_right {
223 $$ = tree_malloc(ST_OP);
226 $$->pt.op.right = $3;
228 | ass_right '/' ass_right {
229 $$ = tree_malloc(ST_OP);
232 $$->pt.op.right = $3;
239 tree_malloc(int type)
242 temp = xmalloc(sizeof (struct tree));
249 yyerror (char const *s)
251 fprintf (stderr, "Line %d: %s\n", line, s);