-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expr.h
176 lines (130 loc) · 3.16 KB
/
Expr.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#pragma once
#include "Token.h"
#include "ListToken.h"
#include "ListExpr.h"
struct Block;
enum ExprType
{
ExprType_Assign,
ExprType_Ternary,
ExprType_Binary,
ExprType_Logical,
ExprType_Grouping,
ExprType_Literal,
ExprType_Set,
ExprType_Super,
ExprType_This,
ExprType_Unary,
ExprType_Variable,
ExprType_Call,
ExprType_Get,
ExprType_Lambda,
};
struct Expr
{
ExprType type;
Expr(ExprType type) : type(type) {}
virtual ~Expr() {}
};
struct Assign : public Expr
{
Token *name;
Expr *value;
Assign(Token *name, Expr *value) : Expr(ExprType_Assign), name(name), value(value) {}
~Assign();
};
struct Ternary : public Expr
{
Expr *first;
Token *oper1;
Expr *second;
Token *oper2;
Expr *third;
Ternary(Expr *first, Token *oper1, Expr *second, Token *oper2, Expr *third) : Expr(ExprType_Ternary), first(first), oper1(oper1), second(second), oper2(oper2), third(third) {}
~Ternary();
};
struct Binary : public Expr
{
Expr *left;
Token *oper;
Expr *right;
Binary(Expr *left, Token *oper, Expr *right) : Expr(ExprType_Binary), left(left), oper(oper), right(right) {}
~Binary();
};
struct Logical : public Expr
{
Expr *left;
Token *oper;
Expr *right;
Logical(Expr *left, Token *oper, Expr *right) : Expr(ExprType_Logical), left(left), oper(oper), right(right) {}
~Logical();
};
struct Grouping : public Expr
{
Expr *expression;
Grouping(Expr *expression) : Expr(ExprType_Grouping), expression(expression) {}
~Grouping();
};
struct Literal : public Expr
{
Object *value;
Literal(Object *value) : Expr(ExprType_Literal), value(value) {}
~Literal();
};
struct Set : public Expr
{
Expr *object;
Token *name;
Expr *value;
Set(Expr *object, Token *name, Expr *value) : Expr(ExprType_Set), object(object), name(name), value(value) {}
~Set();
};
struct Super : public Expr
{
Token *keyword;
Token *method;
Super(Token *keyword, Token *method) : Expr(ExprType_Super), keyword(keyword), method(method) {}
~Super();
};
struct This : public Expr
{
Token *keyword;
This(Token *keyword) : Expr(ExprType_This), keyword(keyword) {}
~This();
};
struct Unary : public Expr
{
Token *oper;
Expr *right;
Unary(Token *oper, Expr *right) : Expr(ExprType_Unary), oper(oper), right(right) {}
~Unary();
};
struct Variable : public Expr
{
Token *name;
Variable(Token *name) : Expr(ExprType_Variable), name(name) {}
~Variable();
};
struct Call : public Expr
{
Expr *callee;
Token *paren;
ListExpr *arguments;
Call(Expr *callee, Token *paren, ListExpr *arguments) : Expr(ExprType_Call), callee(callee), paren(paren), arguments(arguments) {}
~Call();
};
struct Get : public Expr
{
Expr *object;
Token *name;
Get(Expr *object, Token *name) : Expr(ExprType_Get), object(object), name(name) {}
~Get();
};
struct Lambda : public Expr
{
Token *keyword;
ListToken *params;
Block *body;
Lambda(Token *keyword, ListToken *params, Block *body) : Expr(ExprType_Lambda), keyword(keyword), params(params), body(body) {}
~Lambda();
};