-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatements.hpp
More file actions
196 lines (146 loc) · 4.39 KB
/
Statements.hpp
File metadata and controls
196 lines (146 loc) · 4.39 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// Created by smith on 3/20/2019.
//
#ifndef EXPRINTER_STATEMENTS_HPP
#define EXPRINTER_STATEMENTS_HPP
#include <iostream>
#include <vector>
#include "ArithExpr.hpp"
#include "SymTab.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(std::string lhsVar, ExprNode *rhsExpr, bool isArray );
AssignmentStatement(std::string lhsVar, TypeDescriptor sub, ExprNode *rhsExpr, bool isArray );
std::string &lhsVariable();
ExprNode *&rhsExpression();
bool &isArray();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
TypeDescriptor _sub;
std::string _lhsVariable;
ExprNode *_rhsExpression;
bool _isarray;
};
// PrintStatement
class PrintStatement : public Statement {
public:
PrintStatement();
PrintStatement(std::string lhsVar, ExprNode *rhsExpr);
std::string &lhsVariable();
ExprNode *&rhsExpression();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
std::string _lhsVariable;
ExprNode *_rhsExpression;
};
// ForStatement
class ForStatement : public Statement {
public:
ForStatement();
ForStatement(ExprNode *firstExpr, ExprNode *secondExpr, Statements *firstState);
ExprNode *&firstExpr();
ExprNode *&secondExpr();
Statements *&firstState();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
ExprNode *_firstExpr;
ExprNode *_secondExpr;
Statements *_firstState;
};
// Function
class Function : public Statement {
public:
Function();
Function(std::string Expr, std::vector<std::string> parameterList, Statements *statement, bool isCall);
Function(std::string Expr, Function *func, ExprNode *ExprParam, bool isCall);
Function(std::string Expr, Function *func, bool isCall);
std::vector<std::string> ¶meterList();
Statements *&statement();
void evaluate(SymTab &symTab);
void print();
private:
std::string _Expr;
Statements * _statement;
Function *_func;
ExprNode *_ExprParam;
std::vector<std::string> _parameterList;
bool _isCall;
TypeDescriptor _returnValue;
};
// Return
class ReturnStatement : public Statement {
public:
ReturnStatement();
ReturnStatement(std::string, ExprNode *Expr);
ExprNode *&Expr();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
std::string _varName;
ExprNode *_Expr;
};
// If Statement
class IfStatement : public Statement {
public:
IfStatement();
IfStatement(ExprNode *ifExpr, Statements *ifStatements,
std::vector<ExprNode *> elifExpr,
std::vector<Statements *> elifStatements, Statements *elseStatements,
bool isElseTrue);
ExprNode *&ifExpr();
Statements *&ifStatements();
Statements *&elseStatements();
void evaluate(SymTab &symTab);
void print();
private:
ExprNode *_ifExpr;
Statements *_ifStatements;
std::vector<ExprNode *> _elifExpr;
std::vector<Statements *> _elifStatements;
Statements *_elseStatements;
bool _isElseTrue;
};
// Array_ops
class Array_ops : public Statement {
public:
Array_ops();
Array_ops(std::string lhsVar, ExprNode *rhsExpr, bool isAppend );
std::string &lhsVariable();
ExprNode *&rhsExpression();
bool &isAppend();
virtual void evaluate(SymTab &symTab);
virtual void print();
private:
std::string _lhsVariable;
ExprNode *_rhsExpression;
bool _isappend;
};
#endif //EXPRINTER_STATEMENTS_HPP