-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodes.h
68 lines (59 loc) · 1.33 KB
/
nodes.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
#ifndef __NODES_H__
#define __NODES_H__
//Types of nodes
typedef enum{
value_type_node,
var_type_node,
operator_type_node,
block_type_node
}node_type;
//Types of literals
typedef enum{
long_type,
double_type,
string_type
}value_val_type;
//Literal node content.
typedef struct{
value_val_type type;
union{
long l;
double d;
char *s;
};
}value_type;
//Variable node content.
typedef struct{
//The name is used to access the AVL Tree.
char *name;
}var_type;
//Operator node content
typedef struct{
int operator;
int num_operators;
struct AST_node_s **operators;
}operator_type;
typedef struct{
int num_lines;
struct AST_node_s **lines;
}block_type;
typedef struct AST_node_s{
node_type type;
//Nodes are single typed, therefore, union.
union{
value_type value;
var_type variable;
operator_type operator;
block_type block;
};
}AST_node_t;
extern AST_node_t* value_l(long value);
extern AST_node_t* value_d(double value);
extern AST_node_t* value_s(char *value);
extern AST_node_t* variable(char *name);
extern AST_node_t* operator(int operator, int num_operators, ...);
extern AST_node_t* block(AST_node_t *line);
extern AST_node_t* add_line(AST_node_t *block, AST_node_t *line);
extern void execute(AST_node_t *node);
extern void dellocate_node(AST_node_t *node);
#endif