12 void yyerror (char const *);
14 int regex_cmp(char* s, char* r);
15 struct tree* tree_malloc(int type);
16 void print_tree(struct tree* t, int ind);
26 } st; /* subtree type */
29 struct tree* c; /* condition */
30 struct tree* i; /* if */
31 struct tree* e; /* else */
38 } cond; /* binary operator */
65 struct tree* input_tree;
78 %token KW_PIPE KW_MAIL KW_COPY
79 %token '(' ')' '{' '}' ';'
83 %left <n> EQ NEQ GE LE '<' '>' RE NRE
102 input: /* empty */ { $$ = input_tree = NULL; }
103 | command input { $$ = tree_malloc(ST_BLOCK);
104 $$->pt.block.head = $1;
105 $$->pt.block.tail = $2;
111 command: ';' { $$ = tree_malloc(ST_EMPTY); }
112 | '{' command next '}' {
113 $$ = tree_malloc(ST_BLOCK);
114 $$->pt.block.head = $2;
115 $$->pt.block.tail = $3;
117 | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
124 next: /* empty */ {$$ = NULL}
130 cif: KW_IF cond command KW_ELSE command {
131 $$ = tree_malloc(ST_IF);
136 | KW_IF cond command {
137 $$ = tree_malloc(ST_IF);
145 $$ = tree_malloc(ST_COND);
146 $$->pt.cond.left = $2;
147 $$->pt.cond.right = NULL;
152 $$ = tree_malloc(ST_COND);
153 $$->pt.cond.left = $1;
154 $$->pt.cond.right = $3;
159 $$ = tree_malloc(ST_COND);
160 $$->pt.cond.left = $1;
161 $$->pt.cond.right = $3;
166 $$ = tree_malloc(ST_COND);
167 $$->pt.cond.left = $1;
168 $$->pt.cond.right = $3;
172 | '(' cond ')' { $$ = $2; }
173 | ass_right rop ass_right {
174 $$ = tree_malloc(ST_COND);
175 $$->pt.cond.left = $1;
176 $$->pt.cond.right = $3;
193 $$ = tree_malloc(ST_ASS);
195 $$->pt.ass.left = tree_malloc(ST_LEAF);
196 $$->pt.ass.left->pt.leaf.type = L_VAR;
197 $$->pt.ass.left->pt.leaf.value.s = $1;
199 $$->pt.ass.right = $3;
204 $$ = tree_malloc(ST_LEAF);
205 $$->pt.leaf.type = L_NUM;
206 $$->pt.leaf.value.n = $1;
209 $$ = tree_malloc(ST_LEAF);
210 $$->pt.leaf.type = L_VAR;
211 $$->pt.leaf.value.s = $1;
214 $$ = tree_malloc(ST_LEAF);
215 $$->pt.leaf.type = L_CONST;
216 $$->pt.leaf.value.s = $1;
224 tree_malloc(int type)
227 temp = xmalloc(sizeof (struct tree));
234 regex_cmp(char* s, char* r)
239 int ovector[OVECCOUNT];
241 brum = pcre_compile(r,0,&error,&erroroffset,NULL);
245 int res = pcre_exec(brum,NULL,s,strlen(s),0,0,ovector,OVECCOUNT);
252 yyerror (char const *s)
254 fprintf (stderr, "%s\n", s);
258 print_ind(int num, char c)
262 for (i = 0; i < num; i++){
268 print_tree(struct tree* t, int ind)
277 print_tree(t->pt.tif.c,ind+1);
280 print_tree(t->pt.tif.i,ind+1);
283 print_tree(t->pt.tif.e,ind+1);
286 #define UPPER(a) ((a) >> 8)
287 #define LOWER(a) ((a) & 0xFF)
288 print_tree(t->pt.cond.left, ind+1);
291 if (UPPER(t->pt.cond.op) > 0)
292 putchar(UPPER(t->pt.cond.op));
293 putchar(LOWER(t->pt.cond.op));
295 print_tree(t->pt.cond.right, ind+1);
298 print_tree(t->pt.block.head,ind);
299 print_tree(t->pt.block.tail,ind);
302 print_tree(t->pt.ass.left, ind+1);
305 print_tree(t->pt.ass.right, ind+1);
309 switch (t->pt.leaf.type){
313 puts(t->pt.leaf.value.s);
316 printf("%d\n",t->pt.leaf.value.n);
334 print_tree(input_tree,0);