-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
75 lines (65 loc) · 1.61 KB
/
ast.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* stores synbols and values */
struct symbol
{
char *name; /* Var. name*/
double value; /* Value*/
struct ast *func; /* stmt for the function */
struct symlist *syms;
};
/* table of symbols */
struct symbol symtab[50];
struct symbol *lookup(char*);
enum bifs
{ /* built-in functions type */
my_sqrt = 1,
print
};
/* nodes in the Abstract Syntax Tree */
/* all have common initial nodetype */
/* this nodetype changes based on the op to be preformed */
struct ast
{
int nodetype;
struct ast *l;
struct ast *r;
};
struct fncall
{ /* built-in function */
int nodetype; /* Function */
struct ast *l;
enum bifs functype;
};
struct flow
{
int nodetype; /* If or While */
struct ast *cond; /* condition */
struct ast *tl; /* then or do */
struct ast *el; /* else */
};
struct numval
{
int nodetype; /* Number */
double number;
};
struct symref
{
int nodetype; /* Symbol */
struct symbol *s;
};
struct symasgn
{
int nodetype; /* Assignment */
struct symbol *s;
struct ast *v; /* value */
};
struct ast *ast(int nodetype, struct ast *l, struct ast *r);
struct ast *cmp(int cmptype, struct ast *l, struct ast *r);
struct ast *func(int functype, struct ast *l);
struct ast *reference(struct symbol *s);
struct ast *assignment(struct symbol *s, struct ast *v);
struct ast *number(double d);
struct ast *flow(int nodetype, struct ast *cond, struct ast *tl, struct ast *tr);
static double callbuiltin(struct fncall*);
double eval(struct ast *);
void yyerror(char *s, ...);
int yywrap();