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); }
83 cif: KW_IF cond command KW_ELSE command {
84 $$ = tree_malloc(ST_IF);
89 | KW_IF cond command {
90 $$ = tree_malloc(ST_IF);
93 $$->pt.tif.e = tree_malloc(ST_EMPTY);
98 $$ = tree_malloc(ST_COND);
99 $$->pt.cond.left = $2;
100 $$->pt.cond.right = NULL;
102 $$->pt.cond.type = OP_BOOL;
105 $$ = tree_malloc(ST_COND);
106 $$->pt.cond.left = $1;
107 $$->pt.cond.right = $3;
109 $$->pt.cond.type = OP_BOOL;
112 $$ = tree_malloc(ST_COND);
113 $$->pt.cond.left = $1;
114 $$->pt.cond.right = $3;
116 $$->pt.cond.type = OP_BOOL;
119 $$ = tree_malloc(ST_COND);
120 $$->pt.cond.left = $1;
121 $$->pt.cond.right = $3;
123 $$->pt.cond.type = OP_BOOL;
126 | '(' cond ')' { $$ = $2; }
127 | ass_right rop ass_right {
128 $$ = tree_malloc(ST_COND);
129 $$->pt.cond.left = $1;
130 $$->pt.cond.right = $3;
132 $$->pt.cond.type = OP_REL;
135 $$ = tree_malloc(ST_COND);
136 $$->pt.cond.left = $1;
137 $$->pt.cond.type = JUST_BOOL;
152 VAR '=' ass_right_p {
153 $$ = tree_malloc(ST_ASS);
155 $$->pt.ass.left = tree_malloc(ST_LEAF);
156 $$->pt.ass.left->pt.leaf.type = L_VAR;
157 $$->pt.ass.left->pt.leaf.value = $1;
158 $$->pt.ass.left->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
159 $$->pt.ass.right = $3;
164 $$ = tree_malloc(ST_LEAF);
165 $$->pt.leaf.type = L_VAR;
166 $$->pt.leaf.value = $1;
167 $$->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
170 $$ = tree_malloc(ST_LEAF);
171 $$->pt.leaf.type = L_CONST;
172 $$->pt.leaf.value = $1;
173 $$->pt.leaf.n = store_const($1);
177 arrow: left ARROW right ass_right {
178 $$ = tree_malloc(ST_ARROW);
180 $$->pt.arrow.left = $1;
181 $$->pt.arrow.right = $3;
183 | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
184 $$ = tree_malloc(ST_ARROW);
185 $$->pt.arrow.s = NULL;
186 $$->pt.arrow.left = K_EMPTY;
187 $$->pt.arrow.right = K_DISCARD;
191 left: /* empty */ { $$ = K_EMPTY;}
192 | KW_COPY { $$ = K_COPY; }
196 right: /* empty */ { $$ = K_EMPTY; }
197 | KW_PIPE { $$ = K_PIPE; }
198 | KW_MAIL { $$ = K_MAIL; }
199 | KW_FILTER { $$ = K_FILTER; }
202 ass_right_p: '(' ass_right ')' {$$ = $2; }
203 | ass_right {$$ = $1; }
207 | ass_right '.' ass_right {
208 $$ = tree_malloc(ST_OP);
211 $$->pt.op.right = $3;
213 | ass_right '+' ass_right {
214 $$ = tree_malloc(ST_OP);
217 $$->pt.op.right = $3;
219 | ass_right '-' ass_right {
220 $$ = tree_malloc(ST_OP);
223 $$->pt.op.right = $3;
225 | ass_right '*' ass_right {
226 $$ = tree_malloc(ST_OP);
229 $$->pt.op.right = $3;
231 | ass_right '/' ass_right {
232 $$ = tree_malloc(ST_OP);
235 $$->pt.op.right = $3;
242 tree_malloc(int type)
245 temp = xmalloc(sizeof (struct tree));
252 get_var_type(char* var)
274 yyerror (char const *s)
276 fprintf (stderr, "Line %d: %s\n Saving your e-mail to default mailbox %s\n",
277 line, s, default_mailbox);