#include <stdio.h>
#include <stdlib.h>
struct tree {
   int label;
   struct tree *children[2];
   };

#define PLUS 1001

struct tree *leaf(int lab)
{
   struct tree *t = (struct tree *)malloc(sizeof (struct tree));
   t->label = lab;
   return t;
}

struct tree *unary(int lab, struct tree *t2)
{
   struct tree *t = (struct tree *)malloc(sizeof (struct tree));
   t->label = lab;
   t->children[0] = t2;
   return t;
}

struct tree *binary(int lab, struct tree *t2, struct tree *t3)
{
   struct tree *t = (struct tree *)malloc(sizeof (struct tree));
   t->label = lab;
   t->children[0] = t2;
   t->children[1] = t3;
   return t;
}

int go_do_treestuff()
{
   struct tree *t = leaf(1);
   struct tree *t2 = leaf(2);
   struct tree *t3 = binary(PLUS, t, t2);
   int i = eval_traverse(t3);
   printf("evaluates to %d\n", i);
}

int eval_traverse(struct tree *t)
{
   int i;
   printf("%d\n", t->label);
   for(i=0; i<2; i++)
      eval_traverse(t->children[i]);
}
