-
Notifications
You must be signed in to change notification settings - Fork 0
/
treenode.h
93 lines (77 loc) · 1.21 KB
/
treenode.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
#ifndef TREENODE_H
#define TREENODE_H
#include <stddef.h>
#include <string>
#include "token.h"
enum NodeKind
{
StmtSeqK, StmtK, ExprK
};
enum StmtKind
{
IfK, RepeatK, AssignK, ReadK, WriteK
};
enum ExprKind
{
OpK, ConstK, IdK
};
/* ExprType is used for type checking */
enum ExprType
{
Void, Integer, Boolean
};
struct TreeNode
{
TreeNode()
: child(0)
, sibling(0)
, line_no(0)
{
}
TreeNode * child;
TreeNode * sibling;
size_t line_no;
NodeKind kind;
StmtKind stmt_kind;
ExprKind expr_kind;
TokenType op;
int value;
std::string name;
//type check
ExprType expr_type;
};
//struct StmtNode : public TreeNode
//{
// StmtNode() : kind(StmtK) {}
//
// StmtKind stmt_kind;
//};
//
//struct ExprNode : public TreeNode
//{
// ExprNode() : kind(ExprK) {}
//
// ExprKind expr_kind;
//};
//
//struct IdNode : public ExprNode
//{
// IdNode() : expr_kind(IdK) {}
//
// std::string name;
//};
//
//struct ConstNode : public ExprNode
//{
// ConstNode() : expr_kind(ConstK) {}
//
// int value;
//};
//
//struct OpNode : public ExprNode
//{
// OpNode() : expr_kind(OpK) {}
//
// TokenType op;
//};
#endif // TREENODE_H