9 static struct tree* tree_malloc(int type);
10 static enum var_type get_var_type(char* var);
26 %token <n> KW_PIPE KW_MAIL KW_COPY KW_FILTER
27 %token '(' ')' '{' '}' ';'
31 %left <n> EQ NEQ GE LE '<' '>' RE NRE
44 %type <tr> ass_right_p
54 input: /* empty */ { $$ = input_tree = tree_malloc(ST_EMPTY); }
55 | command input { $$ = tree_malloc(ST_BLOCK);
56 $$->pt.block.head = $1;
57 $$->pt.block.tail = $2;
63 command: ';' { $$ = tree_malloc(ST_EMPTY); }
64 | '{' command next '}' {
65 $$ = tree_malloc(ST_BLOCK);
66 $$->pt.block.head = $2;
67 $$->pt.block.tail = $3;
69 | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
71 | ass ';' { $$ = $1; }
72 | arrow ';' { $$ = $1; }
77 next: /* empty */ {$$ = tree_malloc(ST_EMPTY); }
84 cif: KW_IF cond command KW_ELSE command {
85 $$ = tree_malloc(ST_IF);
90 | KW_IF cond command {
91 $$ = tree_malloc(ST_IF);
94 $$->pt.tif.e = tree_malloc(ST_EMPTY);
99 $$ = tree_malloc(ST_COND);
100 $$->pt.cond.left = $2;
101 $$->pt.cond.right = NULL;
103 $$->pt.cond.type = OP_BOOL;
106 $$ = tree_malloc(ST_COND);
107 $$->pt.cond.left = $1;
108 $$->pt.cond.right = $3;
110 $$->pt.cond.type = OP_BOOL;
113 $$ = tree_malloc(ST_COND);
114 $$->pt.cond.left = $1;
115 $$->pt.cond.right = $3;
117 $$->pt.cond.type = OP_BOOL;
120 $$ = tree_malloc(ST_COND);
121 $$->pt.cond.left = $1;
122 $$->pt.cond.right = $3;
124 $$->pt.cond.type = OP_BOOL;
127 | '(' cond ')' { $$ = $2; }
128 | ass_right rop ass_right {
129 $$ = tree_malloc(ST_COND);
130 $$->pt.cond.left = $1;
131 $$->pt.cond.right = $3;
133 $$->pt.cond.type = OP_REL;
136 $$ = tree_malloc(ST_COND);
137 $$->pt.cond.left = $1;
138 $$->pt.cond.type = JUST_BOOL;
153 VAR '=' ass_right_p {
154 $$ = tree_malloc(ST_ASS);
156 $$->pt.ass.left = tree_malloc(ST_LEAF);
157 $$->pt.ass.left->pt.leaf.type = L_VAR;
158 $$->pt.ass.left->pt.leaf.value = $1;
159 $$->pt.ass.left->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
160 $$->pt.ass.right = $3;
165 $$ = tree_malloc(ST_LEAF);
166 $$->pt.leaf.type = L_VAR;
167 $$->pt.leaf.value = $1;
168 $$->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
171 $$ = tree_malloc(ST_LEAF);
172 $$->pt.leaf.type = L_CONST;
173 $$->pt.leaf.value = $1;
174 $$->pt.leaf.n = store_const($1);
178 arrow: left ARROW right ass_right {
179 $$ = tree_malloc(ST_ARROW);
181 $$->pt.arrow.left = $1;
182 $$->pt.arrow.right = $3;
184 | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
185 $$ = tree_malloc(ST_ARROW);
186 $$->pt.arrow.s = NULL;
187 $$->pt.arrow.left = K_EMPTY;
188 $$->pt.arrow.right = K_DISCARD;
192 left: /* empty */ { $$ = K_EMPTY;}
193 | KW_COPY { $$ = K_COPY; }
197 right: /* empty */ { $$ = K_EMPTY; }
198 | KW_PIPE { $$ = K_PIPE; }
199 | KW_MAIL { $$ = K_MAIL; }
200 | KW_FILTER { $$ = K_FILTER; }
203 ass_right_p: '(' ass_right ')' {$$ = $2; }
204 | ass_right {$$ = $1; }
208 | ass_right '.' ass_right {
209 $$ = tree_malloc(ST_OP);
212 $$->pt.op.right = $3;
214 | ass_right '+' ass_right {
215 $$ = tree_malloc(ST_OP);
218 $$->pt.op.right = $3;
220 | ass_right '-' ass_right {
221 $$ = tree_malloc(ST_OP);
224 $$->pt.op.right = $3;
226 | ass_right '*' ass_right {
227 $$ = tree_malloc(ST_OP);
230 $$->pt.op.right = $3;
232 | ass_right '/' ass_right {
233 $$ = tree_malloc(ST_OP);
236 $$->pt.op.right = $3;
243 tree_malloc(int type)
246 temp = xmalloc(sizeof (struct tree));
253 get_var_type(char* var)
275 yyerror (char const *s)
277 fprintf (stderr, "Line %d: %s\n Saving your e-mail to default mailbox %s\n",
278 line, s, default_mailbox);