-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStatements.hpp
More file actions
157 lines (118 loc) · 3.61 KB
/
Statements.hpp
File metadata and controls
157 lines (118 loc) · 3.61 KB
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
#ifndef EXPRINTER_STATEMENTS_HPP
#define EXPRINTER_STATEMENTS_HPP
#include <iostream>
#include <vector>
#include "ArithExpr.hpp"
#include "SymTab.hpp"
#include "Range.hpp"
// The Statement (abstract) class serves as a super class for all statements that
// are defined in the language. Ultimately, statements have to be evaluated.
// Therefore, this class defines evaluate, a pure-virtual function to make
// sure that all subclasses of Statement provide an implementation for this
// function.
class Statement {
public:
Statement();
virtual void print() = 0;
virtual void evaluate(SymTab &symTab) = 0;
};
// Statements is a collection of Statement. For example, all statements in a function
// can be represented by an instance of Statements.
class Statements {
public:
Statements();
void addStatement(Statement *statement);
void evaluate(SymTab &symTab);
void print();
private:
std::vector<Statement *> _statements;
};
// AssignmentStatement represents the notion of an lValue having been assigned an rValue.
// The rValue is an expression.
class AssignmentStatement : public Statement {
public:
AssignmentStatement();
AssignmentStatement(ExprNode *lhsExpr, ExprNode *rhsExpr);
AssignmentStatement(ExprNode *lhsExpr, std::vector<ExprNode*> rhsArray);
ExprNode *&lhsExpression();
ExprNode *&rhsExpression();
std::vector<ExprNode*> rhsArray();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
ExprNode *_lhsExpression;
ExprNode *_rhsExpression;
std::vector<ExprNode*> _rhsArray;
};
class PrintStatement : public Statement {
public:
PrintStatement();
PrintStatement(std::vector<ExprNode*> list);
std::vector<ExprNode*> &list();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
std::vector<ExprNode*> _list;
};
class ForStatement : public Statement {
public:
ForStatement();
ForStatement(Token loopVar, std::vector<ExprNode*> rangeArgs, Statements *body);
Token &loopVar();
std::vector<ExprNode*> &rangeArgs();
Statements *&body();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
Token _loopVar;
std::vector<ExprNode*> _rangeArgs;
Statements *_body;
};
class IfStatement : public Statement {
public:
IfStatement();
IfStatement(std::vector<ExprNode*> conditions, std::vector<Statements*> bodies);
std::vector<ExprNode*> &conditions();
std::vector<Statements*> &bodies();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
std::vector<ExprNode*> _conditions;
std::vector<Statements*> _bodies;
};
class ArrayOpStatement : public Statement {
public:
ArrayOpStatement();
ArrayOpStatement(Token varName, ExprNode* arg);
Token &varName();
ExprNode *&arg();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
Token _varName;
ExprNode* _arg;
};
class CallStatement : public Statement {
public:
CallStatement(Token funcName, std::vector<std::string> params, std::vector<ExprNode*> args, Statements* body);
std::vector<ExprNode*> &args();
std::vector<std::string> ¶ms();
Statements *&body();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
Token _funcName;
std::vector<std::string> _params;
std::vector<ExprNode*> _args;
Statements* _body;
};
class ReturnStatement : public Statement {
public:
ReturnStatement(ExprNode* retVal);
ExprNode *&retVal();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
ExprNode *_retVal;
};
#endif //EXPRINTER_STATEMENTS_HPP