--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <pcre.h>
+
+#include "cond.tab.h"
+#include "brum.h"
+
+#define OVECCOUNT 3
+
+#define HASHSIZE 103
+#define MAGIC 19
+
+struct variable {
+ char* name;
+ char* value;
+ struct variable* next;
+};
+
+struct variable**
+new_var_hash(void)
+{
+ struct variable** res;
+
+ res = xmalloc (HASHSIZE * sizeof(struct variable*));
+ memset(res, 0, sizeof(struct variable*)*HASHSIZE);
+
+ return res;
+}
+
+int
+get_bucket_number(char* name)
+{
+ unsigned int n = 0;
+ unsigned char* p = name;
+
+ while (*p != '\0'){
+ n = n * MAGIC + *p++;
+ }
+ n %= HASHSIZE;
+
+ return n;
+}
+
+/* value NULL for finding without modyfiing */
+struct variable*
+find_var(char* name, char* value, struct variable** hash)
+{
+ int n;
+ struct variable *p;
+
+ n = get_bucket_number(name);
+
+ p = hash[n];
+ while(p && strcmp(p->name,name))
+ p = p->next;
+
+ if (!value)
+ return p;
+ if (p)
+ free(p->value);
+ else {
+ p = xmalloc(sizeof(struct variable));
+ p->next = hash[n]->next;
+ hash[n]->next = p;
+ p->name = xstrdup(name);
+ }
+
+ p->value = xstrdup(value);
+
+ return p;
+}
+
+static void
+print_ind(int num, char c)
+{
+ int i;
+
+ for (i = 0; i < num; i++){
+ putchar(c);
+ }
+//printf("%*s", num, "");
+}
+
+static 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
+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;
+
+
+ }
+}
+
+void
+interp(struct tree* t)
+{
+ if (!t)
+ return;
+
+ switch(t->st){
+ case ST_BLOCK:
+ interp(t->pt.block.head);
+ interp(t->pt.block.tail);
+ break;
+ case ST_ASS:
+
+ break;
+ }
+
+};