8 static struct tree* tree_malloc(int type);
23 %token <n> KW_PIPE KW_MAIL KW_COPY
24 %token '(' ')' '{' '}' ';'
28 %left <n> EQ NEQ GE LE '<' '>' RE NRE
51 input: /* empty */ { $$ = input_tree = tree_malloc(ST_EMPTY); }
52 | command input { $$ = tree_malloc(ST_BLOCK);
53 $$->pt.block.head = $1;
54 $$->pt.block.tail = $2;
60 command: ';' { $$ = tree_malloc(ST_EMPTY); }
61 | '{' command next '}' {
62 $$ = tree_malloc(ST_BLOCK);
63 $$->pt.block.head = $2;
64 $$->pt.block.tail = $3;
66 | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
68 | ass ';' { $$ = $1; }
69 | arrow ';' { $$ = $1; }
74 next: /* empty */ {$$ = tree_malloc(ST_EMPTY); }
80 cif: KW_IF cond command KW_ELSE command {
81 $$ = tree_malloc(ST_IF);
86 | KW_IF cond command {
87 $$ = tree_malloc(ST_IF);
90 $$->pt.tif.e = tree_malloc(ST_EMPTY);
95 $$ = tree_malloc(ST_COND);
96 $$->pt.cond.left = $2;
97 $$->pt.cond.right = NULL;
99 $$->pt.cond.type = OP_BOOL;
102 $$ = tree_malloc(ST_COND);
103 $$->pt.cond.left = $1;
104 $$->pt.cond.right = $3;
106 $$->pt.cond.type = OP_BOOL;
109 $$ = tree_malloc(ST_COND);
110 $$->pt.cond.left = $1;
111 $$->pt.cond.right = $3;
113 $$->pt.cond.type = OP_BOOL;
116 $$ = tree_malloc(ST_COND);
117 $$->pt.cond.left = $1;
118 $$->pt.cond.right = $3;
120 $$->pt.cond.type = OP_BOOL;
123 | '(' cond ')' { $$ = $2; }
124 | ass_right rop ass_right {
125 $$ = tree_malloc(ST_COND);
126 $$->pt.cond.left = $1;
127 $$->pt.cond.right = $3;
129 $$->pt.cond.type = OP_REL;
132 $$ = tree_malloc(ST_COND);
133 $$->pt.cond.left = $1;
134 $$->pt.cond.type = JUST_BOOL;
150 $$ = tree_malloc(ST_ASS);
152 $$->pt.ass.left = tree_malloc(ST_LEAF);
153 $$->pt.ass.left->pt.leaf.type = L_VAR;
154 $$->pt.ass.left->pt.leaf.value = $1;
155 $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash);
156 $$->pt.ass.right = $3;
161 $$ = tree_malloc(ST_LEAF);
162 $$->pt.leaf.type = L_VAR;
163 $$->pt.leaf.value = $1;
164 $$->pt.leaf.n = find_var($1, var_hash);
167 $$ = tree_malloc(ST_LEAF);
168 $$->pt.leaf.type = L_CONST;
169 $$->pt.leaf.value = $1;
170 $$->pt.leaf.n = store_const($1);
174 arrow: left ARROW right ass_right {
175 $$ = tree_malloc(ST_ARROW);
177 $$->pt.arrow.left = $1;
178 $$->pt.arrow.right = $3;
180 | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
181 $$ = tree_malloc(ST_ARROW);
182 $$->pt.arrow.s = NULL;
183 $$->pt.arrow.left = K_EMPTY;
184 $$->pt.arrow.right = K_DISCARD;
188 left: /* empty */ { $$ = K_EMPTY;}
189 | KW_COPY { $$ = K_COPY; }
193 right: /* empty */ { $$ = K_EMPTY; }
194 | KW_PIPE { $$ = K_PIPE; }
195 | KW_MAIL { $$ = K_MAIL; }
199 | ass_right '.' ass_right {
200 $$ = tree_malloc(ST_OP);
203 $$->pt.op.right = $3;
210 tree_malloc(int type)
213 temp = xmalloc(sizeof (struct tree));
220 yyerror (char const *s)
222 fprintf (stderr, "Line %d: %s\n", line, s);