-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stmt.h
128 lines (94 loc) · 2.38 KB
/
Stmt.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
#pragma once
#include "Expr.h"
#include "ListStmt.h"
#include "ListToken.h"
#include "ListFunction.h"
enum StmtType
{
StmtType_Expression,
StmtType_Print,
StmtType_Var,
StmtType_Block,
StmtType_Function,
StmtType_Class,
StmtType_If,
StmtType_While,
StmtType_Return,
StmtType_Break,
};
struct Stmt
{
StmtType type;
Stmt(StmtType type) : type(type) {}
virtual ~Stmt() {}
};
struct Expression : public Stmt
{
Expr *expression;
Expression(Expr *expression) : Stmt(StmtType_Expression), expression(expression) {}
~Expression();
};
struct Print : public Stmt
{
Expr *expression;
Print(Expr *expression) : Stmt(StmtType_Print), expression(expression) {}
~Print();
};
struct Var : public Stmt
{
Token *name;
Expr *initializer;
Var(Token *name, Expr *initializer) : Stmt(StmtType_Var), name(name), initializer(initializer) {}
~Var();
};
struct Block : public Stmt
{
ListStmt *statements;
Block(ListStmt *statements) : Stmt(StmtType_Block), statements(statements) {}
~Block();
};
struct Function : public Stmt
{
Token *name;
ListToken *params;
Block *body;
Function(Token *name, ListToken *params, Block *body) : Stmt(StmtType_Function), name(name), params(params), body(body) {}
~Function();
};
struct Class : public Stmt
{
Token *name;
Variable *superclass;
ListFunction *methods;
ListFunction *statics;
Class(Token *name, Variable *superclass, ListFunction *methods, ListFunction *statics) : Stmt(StmtType_Class), name(name), superclass(superclass), methods(methods), statics(statics) {}
~Class();
};
struct If : public Stmt
{
Expr *condition;
Stmt *thenBranch;
Stmt *elseBranch;
If(Expr *condition, Stmt *thenBranch, Stmt *elseBranch) : Stmt(StmtType_If), condition(condition), thenBranch(thenBranch), elseBranch(elseBranch) {}
~If();
};
struct While : public Stmt
{
Expr *condition;
Stmt *body;
While(Expr *condition, Stmt *body) : Stmt(StmtType_While), condition(condition), body(body) {}
~While();
};
struct Return : public Stmt
{
Token *keyword;
Expr *value;
Return(Token *keyword, Expr *value) : Stmt(StmtType_Return), keyword(keyword), value(value) {}
~Return();
};
struct Break : public Stmt
{
Token *keyword;
Break(Token *keyword) : Stmt(StmtType_Break), keyword(keyword) {}
~Break();
};