758d0347a44b4016bfbbdd9d81010cdc4d586186
[ccc.git] / ast.h
1 #ifndef AST_H
2 #define AST_H
3
4 #include <stdio.h>
5
6 enum binop {plus,minus,times,divide};
7 enum ast_type {an_binop, an_cons, an_int};
8 struct ast {
9 enum ast_type type;
10 union {
11 struct {
12 struct ast *l;
13 enum binop op;
14 struct ast *r;
15 } an_binop;
16 struct {
17 struct ast *el;
18 struct ast *tail;
19 } an_cons;
20 int an_int;
21
22 } data;
23 };
24
25 struct ast *ast_cons(struct ast *el, struct ast *tail);
26 struct ast *ast_binop(struct ast *l, enum binop op, struct ast *tail);
27 struct ast *ast_int(int integer);
28
29 void ast_print(struct ast * ast, FILE *out);
30 void ast_free(struct ast *ast);
31
32 #endif