use builtin operator associativity functionality
[ccc.git] / ast.h
1 #ifndef AST_H
2 #define AST_H
3
4 #include <stdio.h>
5
6 enum binop {
7 binor,binand,
8 eq,neq,leq,le,geq,ge,
9 cons,plus,minus,times,divide,modulo,power
10 };
11 enum unop {negate,inverse};
12 enum ast_type {an_binop, an_cons, an_int, an_unop};
13 struct ast {
14 enum ast_type type;
15 union {
16 struct {
17 struct ast *l;
18 enum binop op;
19 struct ast *r;
20 } an_binop;
21 struct {
22 struct ast *el;
23 struct ast *tail;
24 } an_cons;
25 int an_int;
26 struct {
27 enum unop op;
28 struct ast *l;
29 } an_unop;
30
31 } data;
32 };
33
34 struct ast *ast_cons(struct ast *el, struct ast *tail);
35 struct ast *ast_binop(struct ast *l, enum binop op, struct ast *tail);
36 struct ast *ast_int(int integer);
37 struct ast *ast_unop(enum unop op, struct ast *l);
38
39 void ast_print(struct ast * ast, FILE *out);
40 void ast_free(struct ast *ast);
41
42 #endif