9 static struct tree* tree_malloc(int type);
10 static enum var_type get_var_type(char* var);
25 %token <n> KW_PIPE KW_MAIL KW_COPY KW_FILTER
26 %token '(' ')' '{' '}' ';'
30 %left <n> EQ NEQ GE LE '<' '>' RE NRE
45 %type <tr> ass_right_p
55 input_init: input {input_tree = $$}
58 input: /* empty */ { $$ = tree_malloc(ST_EMPTY); }
59 | command input { $$ = tree_malloc(ST_BLOCK);
60 $$->pt.block.head = $1;
61 $$->pt.block.tail = $2;
65 command: ';' { $$ = tree_malloc(ST_EMPTY); }
66 | '{' command input '}' {
67 $$ = tree_malloc(ST_BLOCK);
68 $$->pt.block.head = $2;
69 $$->pt.block.tail = $3;
71 | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
73 | ass ';' { $$ = $1; }
74 | arrow ';' { $$ = $1; }
79 cif: KW_IF cond command KW_ELSE command {
80 $$ = tree_malloc(ST_IF);
85 | KW_IF cond command {
86 $$ = tree_malloc(ST_IF);
89 $$->pt.tif.e = tree_malloc(ST_EMPTY);
94 $$ = tree_malloc(ST_COND);
95 $$->pt.cond.left = $2;
96 $$->pt.cond.right = NULL;
98 $$->pt.cond.type = OP_BOOL;
101 $$ = tree_malloc(ST_COND);
102 $$->pt.cond.left = $1;
103 $$->pt.cond.right = $3;
105 $$->pt.cond.type = OP_BOOL;
108 $$ = tree_malloc(ST_COND);
109 $$->pt.cond.left = $1;
110 $$->pt.cond.right = $3;
112 $$->pt.cond.type = OP_BOOL;
115 $$ = tree_malloc(ST_COND);
116 $$->pt.cond.left = $1;
117 $$->pt.cond.right = $3;
119 $$->pt.cond.type = OP_BOOL;
122 | '(' cond ')' { $$ = $2; }
123 | ass_right rop ass_right {
124 $$ = tree_malloc(ST_COND);
125 $$->pt.cond.left = $1;
126 $$->pt.cond.right = $3;
128 $$->pt.cond.type = OP_REL;
131 $$ = tree_malloc(ST_COND);
132 $$->pt.cond.left = $1;
133 $$->pt.cond.type = JUST_BOOL;
148 VAR '=' ass_right_p {
149 $$ = tree_malloc(ST_ASS);
151 $$->pt.ass.left = tree_malloc(ST_LEAF);
152 $$->pt.ass.left->pt.leaf.type = L_VAR;
153 $$->pt.ass.left->pt.leaf.value = $1;
154 $$->pt.ass.left->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
155 $$->pt.ass.right = $3;
160 $$ = tree_malloc(ST_LEAF);
161 $$->pt.leaf.type = L_VAR;
162 $$->pt.leaf.value = $1;
163 $$->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
166 $$ = tree_malloc(ST_LEAF);
167 $$->pt.leaf.type = L_CONST;
168 $$->pt.leaf.value = $1;
169 $$->pt.leaf.n = store_const($1);
173 arrow: left ARROW right ass_right {
174 $$ = tree_malloc(ST_ARROW);
176 $$->pt.arrow.left = $1;
177 $$->pt.arrow.right = $3;
179 | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
180 $$ = tree_malloc(ST_ARROW);
181 $$->pt.arrow.s = NULL;
182 $$->pt.arrow.left = K_EMPTY;
183 $$->pt.arrow.right = K_DISCARD;
187 left: /* empty */ { $$ = K_EMPTY;}
188 | KW_COPY { $$ = K_COPY; }
192 right: /* empty */ { $$ = K_EMPTY; }
193 | KW_PIPE { $$ = K_PIPE; }
194 | KW_MAIL { $$ = K_MAIL; }
195 | KW_FILTER { $$ = K_FILTER; }
198 ass_right_p: '(' ass_right ')' {$$ = $2; }
199 | ass_right {$$ = $1; }
203 | ass_right '.' ass_right {
204 $$ = tree_malloc(ST_OP);
207 $$->pt.op.right = $3;
209 | ass_right '+' ass_right {
210 $$ = tree_malloc(ST_OP);
213 $$->pt.op.right = $3;
215 | ass_right '-' ass_right {
216 $$ = tree_malloc(ST_OP);
219 $$->pt.op.right = $3;
221 | ass_right '*' ass_right {
222 $$ = tree_malloc(ST_OP);
225 $$->pt.op.right = $3;
227 | ass_right '/' ass_right {
228 $$ = tree_malloc(ST_OP);
231 $$->pt.op.right = $3;
233 | '-' ass_right %prec NEG {
234 $$ = tree_malloc(ST_OP);
236 $$->pt.op.left = tree_malloc(ST_LEAF);
237 $$->pt.op.left->pt.leaf.type = L_CONST;
238 $$->pt.op.left->pt.leaf.value = "0";
239 $$->pt.op.left->pt.leaf.n =
241 $$->pt.op.right = $2;
248 tree_malloc(int type)
251 temp = xmalloc(sizeof (struct tree));
258 get_var_type(char* var)
280 yyerror (char const *s)
282 fprintf (stderr, "Line %d: %s\n Saving your e-mail to default mailbox %s\n",
283 line, s, default_mailbox);