-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
98 lines (83 loc) · 1.71 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef _AST_H_
#define _AST_H_
#include "scanner.h"
#include "datatype.h"
typedef enum
{
AST_GLUE,
AST_EMPTY,
AST_ADD,
AST_SUBTRACT,
AST_MULT,
AST_DIV,
AST_COMP_GT,
AST_COMP_GE,
AST_COMP_LT,
AST_COMP_LE,
AST_COMP_EQ,
AST_COMP_NE,
AST_INT_LIT,
AST_PRINT,
AST_ASSIGN,
AST_VAR,
AST_DATATYPE,
AST_ADDRESSOF,
AST_PTRDREF,
AST_VAR_DECL,
AST_FUNC_DECL,
AST_FUNC_CALL,
AST_RETURN,
AST_IF,
AST_WHILE,
AST_DO_WHILE,
AST_FOR,
AST_BREAK
} ASTNode_type_e;
#define ASTCheckLoopContext(t) t >= AST_WHILE &&t <= AST_FOR
typedef struct ASTNode_t ASTNode_t;
struct ASTNode_t
{
ASTNode_type_e type;
ASTNode_t *next;
ASTNode_t *left;
ASTNode_t *right;
ASTNode_t *parent;
Datatype_t *expr_type;
int value;
};
static char *__ast_type_names[] = {
"AST_GLUE",
"AST_EMPTY",
"AST_ADD",
"AST_SUBTRACT",
"AST_MULT",
"AST_DIV",
"AST_COMP_GT",
"AST_COMP_GE",
"AST_COMP_LT",
"AST_COMP_LE",
"AST_COMP_EQ",
"AST_COMP_NE",
"AST_INT_LIT",
"AST_PRINT",
"AST_ASSIGN",
"AST_VAR",
"AST_DATATYPE",
"AST_ADDRESSOF",
"AST_PTRDREF",
"AST_VAR_DECL",
"AST_FUNC_DECL",
"AST_FUNC_CALL",
"AST_RETURN",
"AST_IF",
"AST_WHILE",
"AST_DO_WHILE",
"AST_FOR",
"AST_BREAK"};
#define NodeToString(node) __ast_type_names[(node).type]
ASTNode_t *ast_create_node(ASTNode_type_e type, ASTNode_t *left, ASTNode_t *right, int value);
ASTNode_t *ast_create_leaf_node(ASTNode_type_e type, int value);
ASTNode_t *ast_get_parent_of_type(ASTNode_t *node, ASTNode_type_e type);
ASTNode_t *ast_flatten(ASTNode_t *node);
void ast_free(ASTNode_t *node);
#endif