]> mj.ucw.cz Git - umpf.git/commitdiff
a bit cleanup and split the main
authorAnicka Bernathova <anicka@anicka.net>
Tue, 8 Jul 2008 14:43:12 +0000 (16:43 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 8 Jul 2008 14:43:12 +0000 (16:43 +0200)
Makefile
cond.y

index 549b9b5b76e4b623f54adacd3c3cf561b6fcb3bb..67e0187dbbd00fd77af4724558b9d94ef217f93d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,18 @@
-all: cond
+all: brum 
 
 CC=gcc
 CFLAGS=-Wall -W -O2 -g
 LDLIBS=-lpcre
 
-cond: cond.tab.o lex.o
+brum: brum.c cond.tab.o int.o lex.o
        gcc -o $@ $^ $(LDLIBS)
 
-cond.tab.o: cond.tab.c
+cond.tab.o: cond.tab.c lex.o
 
 lex.o: lex.c cond.tab.c
 
+int.o: int.c
+
 cond.tab.c: cond.y
        bison -dvt cond.y
 
diff --git a/cond.y b/cond.y
index 8baaf2163306d7d1f58f2eae1a5061c15d1e20e1..4816a03635660129b2a6873b19a8d5ca5e7a4e7c 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -2,84 +2,13 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <pcre.h>
 
 #include "lex.h"
+#include "cond.h"
 
-#define OVECCOUNT 3
-
-int yylex (void);
-void yyerror (char const *);
-
-int regex_cmp(char* s, char* r);
-struct tree* tree_malloc(int type);
-void print_tree(struct tree* t, int ind);
-
-struct tree {
-       enum {
-               ST_IF,
-               ST_COND,
-               ST_BLOCK,
-               ST_ASS,
-               ST_LEAF,
-               ST_EMPTY,
-               ST_ARROW,
-               ST_OP
-       } st;   /* subtree type */
-       union {
-               struct {
-                       struct tree* c; /* condition */
-                       struct tree* i; /* if */
-                       struct tree* e; /* else */
-               } tif;
-
-               struct {
-                       int op;
-                       struct tree* left;
-                       struct tree* right;
-               } cond; /* binary operator */
-
-               struct {
-                       struct tree* head;
-                       struct tree* tail;
-               } block;
-
-               struct {
-                       struct tree* left;
-                       struct tree* right;
-               } ass;
-
-               struct {
-                       enum {
-                               L_VAR,
-                               L_CONST,
-                               L_NUM
-                       } type;
-                       union {
-                               char* s;
-                               int n;
-                       } value;
-               } leaf;
-
-               struct {
-                       char* kw_left;
-                       char* kw_right; 
-                       struct tree* s;
-               } arrow;
-
-               struct {
-                       int op;
-                       struct tree* left;
-                       struct tree* right;
-               } op;
-
-       } pt;
-};
-
-struct tree* input_tree;
+static struct tree* tree_malloc(int type);
 
 %}
-
 %error-verbose
 
 %union {
@@ -136,13 +65,13 @@ command:    ';' { $$ = tree_malloc(ST_EMPTY); }
                                        }
                | '{' '}' { $$ = tree_malloc(ST_EMPTY); }
                | cif
-               | ass ';' { $$ = $1}
-               | arrow ';' { $$ = $1}
+               | ass ';' { $$ = $1}
+               | arrow ';' { $$ = $1}
                
        
 ;
 
-next:  /* empty */ {$$ = NULL}
+next:  /* empty */ {$$ = NULL}
        | command
        
 
@@ -246,14 +175,14 @@ arrow:    left ARROW right ass_right  {
                                }
 ;
 
-left:  /* empty */ {$$=NULL}
-       | KW_COPY { $$ = "copy" }
+left:  /* empty */ {$$=NULL;}
+       | KW_COPY { $$ = "copy"; }
 
 ;
 
-right: /* empty */ {$$ = NULL}
-       | KW_PIPE { $$ = "pipe" }
-       | KW_MAIL { $$ = "mail" }
+right: /* empty */ {$$ = NULL}
+       | KW_PIPE { $$ = "pipe"; }
+       | KW_MAIL { $$ = "mail"; }
 ;
 
 ass_right:     leaves
@@ -277,127 +206,8 @@ tree_malloc(int type)
        return temp;
 }
 
-int 
-regex_cmp(char* s, char* r)
-{
-       pcre *brum;
-       int erroroffset;
-       const char* error;
-       int ovector[OVECCOUNT];
-       
-       brum = pcre_compile(r,0,&error,&erroroffset,NULL);
-       if (!brum)
-               return -1;
-       
-       int res = pcre_exec(brum,NULL,s,strlen(s),0,0,ovector,OVECCOUNT);
-       pcre_free(brum);
-
-       return res;
-}
-
 void
 yyerror (char const *s)
 {
        fprintf (stderr, "Line %d: %s\n", line, s);
 }
-
-void
-print_ind(int num, char c)
-{
-       int i;
-
-       for (i = 0; i < num; i++){
-               putchar(c);
-       }
-}
-
-void
-print_tree(struct tree* t, int ind)
-{
-       if (!t)
-               return; 
-
-       switch (t->st){
-               case ST_IF:
-                       print_ind(ind,' ');
-                       puts("if");
-                       print_tree(t->pt.tif.c,ind+1);
-                       print_ind(ind,' ');
-                       puts("then");
-                       print_tree(t->pt.tif.i,ind+1);
-                       print_ind(ind,' ');
-                       puts("else");
-                       print_tree(t->pt.tif.e,ind+1);
-                       break;
-               case ST_COND:
-#define UPPER(a) ((a) >> 8)
-#define LOWER(a) ((a) & 0xFF)
-                       print_tree(t->pt.cond.left, ind+1);
-                       print_ind(ind,' ');
-
-                       if (UPPER(t->pt.cond.op) > 0)
-                               putchar(UPPER(t->pt.cond.op));
-                       putchar(LOWER(t->pt.cond.op));
-                       putchar('\n'); 
-                       print_tree(t->pt.cond.right, ind+1);    
-                       break;
-               case ST_BLOCK:
-                       print_tree(t->pt.block.head,ind);
-                       print_tree(t->pt.block.tail,ind);
-                       break;
-               case ST_ASS:
-                       print_tree(t->pt.ass.left, ind+1);
-                       print_ind(ind,' ');     
-                       puts("=");
-                       print_tree(t->pt.ass.right, ind+1);
-                       break;
-               case ST_LEAF:
-                       print_ind(ind, ' ');
-                       switch (t->pt.leaf.type){
-                               case L_VAR:
-                                       putchar('$');
-                               case L_CONST:
-                                       puts(t->pt.leaf.value.s);
-                                       break;
-                               case L_NUM:
-                                       printf("%d\n",t->pt.leaf.value.n);
-                                       break;
-                       }
-                       break;
-               case ST_ARROW:
-                       if (t->pt.arrow.kw_left){
-                               print_ind(ind+1, ' ');
-                               puts(t->pt.arrow.kw_left);
-                       }
-                       print_ind(ind, ' ');
-                       printf("->\n");
-                       if (t->pt.arrow.kw_right){
-                               print_ind(ind+1, ' ');
-                               puts(t->pt.arrow.kw_right);
-                       }
-                       print_tree(t->pt.arrow.s,ind+1);
-                       break;
-               case ST_OP:
-                       print_tree(t->pt.op.left, ind+1);
-                       print_ind(ind,' ');     
-                       putchar(t->pt.op.op);
-                       putchar('\n');
-                       print_tree(t->pt.op.right, ind+1);
-                       break;  
-               case ST_EMPTY:
-                       break;  
-
-
-       }
-}
-
-
-int
-main(void)
-{
-//     yydebug=1;
-       yyparse ();
-
-       print_tree(input_tree,0);
-       return 0;
-}