-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.h
More file actions
64 lines (55 loc) · 1.51 KB
/
ast.h
File metadata and controls
64 lines (55 loc) · 1.51 KB
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
#ifndef AST_H
#define AST_H
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct tree_struct *tree;
typedef struct list_struct *list;
enum node_type {
nPROGRAM,
nBLOCK,
nCONST_DECL,
nVAR_DECL,
nPROC_DECL,
nSTMT,
nASSIGN_STMT,
nIF_STMT,
nWHILE_STMT,
nFOR_STMT,
nCALL_STMT,
nREAD_STMT,
nWRITE_STMT,
nID,
};
extern tree root;
struct info {
int type;
};
struct list_struct {
tree node;
list next;
};
struct tree_struct {
struct info val;
list children;
};
void init_tree(); // program
void add_ast(int);
void enter_ast(int);
void leave_ast();
void print_ast();
static const char *node_type_str[] = {[nPROGRAM] = "program",
[nBLOCK] = "block",
[nCONST_DECL] = "const_decl",
[nVAR_DECL] = "var_decl",
[nPROC_DECL] = "proc_decl",
[nSTMT] = "stmt",
[nASSIGN_STMT] = "assign_stmt",
[nIF_STMT] = "if_stmt",
[nWHILE_STMT] = "while_stmt",
[nCALL_STMT] = "call_stmt",
[nREAD_STMT] = "read_stmt",
[nWRITE_STMT] = "write_stmt",
[nID] = "id",
[nFOR_STMT] = "for_stmt(simplified)"};
#endif // AST_H