-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastNode.h
126 lines (109 loc) · 2.31 KB
/
astNode.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include <string>
#include <vector>
#include "varType.h"
enum ASTNodeType {
AST_UNDEFINED,
AST_PROGRAM,
AST_FUNCTION,
AST_DECLARATION,
AST_IDENTIFIER,
AST_NUMBER,
AST_TYPE,
AST_PARAMETERLIST,
AST_PARAMETER,
AST_STATEMENT,
AST_ASSIGNMENT,
AST_EXPRESSION,
AST_BINARYEXPRESSION,
AST_OPERATOR,
AST_KEYWORD,
AST_VARDECLARATION,
AST_FUNCTIONBODY,
AST_ARRAYINDEX,
AST_CHAR,
};
enum StatementType {
STMT_WHILE,
STMT_FOR,
STMT_IF,
STMT_RETURN,
STMT_ASSIGN,
STMT_FUNCTIONCALL,
STMT_BLOCK,
STMT_EMPTY,
// NES-specific statements
STMT_NES_WAITFORFRAME,
STMT_NES_SETSPRITEX,
STMT_NES_SETSPRITEY,
};
struct ASTNode {
explicit ASTNode(ASTNodeType type) {
nodeType = type;
}
ASTNodeType nodeType;
std::vector<ASTNode*> children;
};
struct TypeNode : ASTNode {
TypeNode() : ASTNode(AST_TYPE) {
}
VarType varType;
};
struct IdentifierNode : ASTNode {
IdentifierNode() : ASTNode(AST_IDENTIFIER) {
}
std::string name;
};
struct NumberNode : ASTNode {
NumberNode() : ASTNode(AST_NUMBER) {
}
int value;
};
struct CharNode : ASTNode {
CharNode() : ASTNode(AST_CHAR) {
}
char value;
};
struct OpNode : ASTNode {
OpNode() : ASTNode(AST_OPERATOR) {
}
std::string operation; // TODO enum
};
struct StatementNode : ASTNode {
StatementNode() : ASTNode(AST_STATEMENT) {
}
StatementType type;
};
/*
struct ParameterNode : ASTNode {
TypeNode * paramType;
IdentifierNode * paramName;
};
struct StatementNode : ASTNode {
};
struct FunctionNode : ASTNode {
TypeNode * returnType;
IdentifierNode * functionName;
std::list<ParameterNode *> parameters;
std::list<StatementNode *> statements;
};
struct ProgramNode : ASTNode {
// Can be either FunctionDefinitionNode or DeclarationNode
std::list<void*> programBody;
};
struct DeclarationNode : ASTNode {
TypeNode * type;
IdentifierNode * identifier;
};
struct ExpressionNode : ASTNode {
ExpressionType type;
ExpressionNode * firstParam;
ExpressionNode * secondParam;
// std::list<ExpressionNode> args;
};
struct AssignmentNode : ASTNode {
IdentifierNode * id;
ExpressionNode * newValue;
ExpressionNode * arraySelectorExpression;
};
*/