/* Abstract Syntax Trees for E */

typedef char* id;

typedef struct ExpS *Exp;
typedef struct ExpsS *Exps;
typedef struct idsS *ids;

struct ExpS {
  enum {VarExp=0,ConstExp,PlusExp,MinusExp,
        AsgnExp,If0Exp,BlockExp} kind;
  union {
    struct {
      id i;
    } varexp;
    struct {
      int n;
    } constexp;
    struct {
      Exp l;
      Exp r;
    } plusexp;
    struct {
      Exp l;
      Exp r;
    } minusexp;
    struct {
      id i;
      Exp e;
    } asgnexp;
    struct {
      Exp e;
      Exp t;
      Exp f;
    } if0exp;
    struct {
      ids is;
      Exps es;
    } blockexp;
  } u;
};

struct idsS {
  id i;
  ids next;
};

struct ExpsS {
  Exp e;
  Exps next;
};

/* Utility functions */

void *checked_malloc(int i);

char *strsave(char* s);

/* AST constuctor functions */

Exp mk_VarExp(id i);
Exp mk_ConstExp(int n);
Exp mk_PlusExp(Exp l,Exp r);
Exp mk_MinusExp(Exp l,Exp r);
Exp mk_AsgnExp(id i, Exp e);
Exp mk_If0Exp(Exp e, Exp t, Exp f);
Exp mk_BlockExp(ids is, Exps es);
Exps mk_Exps(Exp e, Exps next);
ids mk_ids(id i, ids next);

