forked from gousiosg/AegeanC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.h
82 lines (80 loc) · 1.56 KB
/
tree.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
76
77
78
79
80
81
82
/*tree.h :syntax tree definitions*/
/*All the possible types of the tree nodes*/
enum nodetypes
{
MYFILE,/*name of the root of the tree*/
PROG,
MAKEFUN,/*a user function definition node*/
INT, /*a variable definition node */
WHILE,
IFELSE,
COMMANDS,/*a node with pointers to all possible commands*/
PUTSTR,
PUTINT,
GETINT,
USERFUN,
BINOP, /*a node for all binary operations*/
CMP, /*a node for comparisons*/
UNOP,
VAR,
NUM
};
struct s_tree
{
enum nodetypes nt;
union
{
struct s_tree *Program;/*points to the rest of the program*/
char *Variable;/*used for constructing a variable node*/
char *String; /*used for constucting a putstring node*/
int Number; /*used for constructing a getint node*/
struct s_prog
{
struct s_tree *variable;
struct s_tree *makefun;
struct s_tree *prog;/*to contruct more PROG nodes*/
}Prog;
struct s_makefun /*User function definition node*/
{
struct s_tree *commands;
char *name;
}Makefun;
struct s_while
{
struct s_tree *cmp;
struct s_tree *commands;
}While;
struct s_ifelse
{
struct s_tree *cmp;
struct s_tree *commands;
struct s_tree *else_commands;
}Ifelse;
struct s_commands
{
struct s_tree *command;
struct s_tree *commands;
}Commands;
struct s_putint
{
struct s_tree *binop;
}Putint;
struct s_binop
{
struct s_tree *left;
struct s_tree *right;
char op;
}Binop;
struct s_cmp
{
struct s_tree *left;
struct s_tree *right;
char *op;
}Cmp;
struct s_unop
{
struct s_tree *exp;
char op;
}Unop;
}u;
};