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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#pragma once
#include <vector>
#include <string>
#include <memory>
#include "TocParser.h"
using namespace std;
struct Type;
struct Variable;
struct Body;
struct Function;
struct Struct;
struct Program;
struct CallExpr;
struct LiteralExpr;
struct VariableExpr;
struct BracketsExpr;
struct OperatorExpr;
struct DotExpr;
struct Expr;
struct IfStmt;
struct WhileStmt;
struct ReturnStmt;
struct AssignStmt;
struct Stmt;
struct Type {
std::string name;
};
struct Variable {
std::string name;
Type type;
};
struct Body {
std::vector<Variable> variables;
std::vector<Stmt> statements;
};
struct Function {
std::string name;
std::vector<Variable> parameters;
Body body;
};
struct Struct {
std::string name;
std::vector<Variable> members;
std::vector<Function> methods;
};
struct Program {
std::vector<Variable> variables;
std::vector<Struct> structs;
std::vector<Function> functions;
};
enum class ExprType {
Call, Literal, Variable, Brackets, Operator, Dot
};
struct CallExpr {
Function function;
std::vector<Expr> arguments;
};
struct LiteralExpr {
int i;
};
struct VariableExpr {
std::string name;
};
struct BracketsExpr {
BracketsExpr() {}
BracketsExpr(const BracketsExpr &) {}
BracketsExpr & operator=(const BracketsExpr &) {return *this;};
std::unique_ptr<Expr> lexpr;
std::unique_ptr<Expr> rexpr;
};
enum class OperatorType {
Plus, Minus, Multiply, Divide,
Equals, NotEquals,
LessThan, GreaterThan
};
struct OperatorExpr {
OperatorExpr() {}
OperatorExpr(const OperatorExpr &) {}
OperatorExpr & operator=(const OperatorExpr &) {return *this;};
std::unique_ptr<Expr> lexpr;
std::unique_ptr<Expr> rexpr;
OperatorType type;
};
struct DotExpr {
DotExpr() {}
DotExpr(const DotExpr &) {}
DotExpr & operator=(const DotExpr &) {return *this;};
std::unique_ptr<Expr> lexpr;
std::string name;
};
struct Expr {
ExprType type;
CallExpr _call;
LiteralExpr _literal;
VariableExpr _variable;
BracketsExpr _brackets;
OperatorExpr _operator;
DotExpr _dot;
};
enum class StmtType {
If, While, Return, Assign, Expr
};
struct IfStmt {
Expr condition;
Body body;
};
struct WhileStmt {
Expr condition;
Body body;
};
struct ReturnStmt {
Expr expr;
};
struct AssignStmt {
Expr lexpr;
Expr rexpr;
};
struct Stmt {
StmtType type;
IfStmt _if;
WhileStmt _while;
ReturnStmt _return;
AssignStmt _assign;
Expr _expr;
};
|