-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.h
169 lines (144 loc) · 3.63 KB
/
Types.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
#ifndef __TYPES_H__
#define __TYPES_H__
#include <string>
#include <iostream>
#include <memory>
#include <list>
#include "SymbolTable.h"
using namespace std;
class Expression {
public:
virtual string toString() = 0;
virtual unique_ptr<Expression> eval() = 0;
virtual unique_ptr<Expression> add(Expression& e) = 0;
virtual unique_ptr<Expression> index(Expression& e) = 0;
friend ostream& operator << (ostream& os, Expression& e);
virtual ~Expression();
};
class Assignable {
public:
virtual void assign(unique_ptr<Expression> rval) = 0;
};
class ScriptVariable : public Expression, public Assignable {
private:
string name;
shared_ptr<SymbolTable> table;
public:
ScriptVariable(shared_ptr<SymbolTable> table, const string & name);
void assign(unique_ptr<Expression> rval);
string toString();
unique_ptr<Expression> eval();
unique_ptr<Expression> add(Expression& e);
unique_ptr<Expression> index(Expression& e);
~ScriptVariable();
};
class ScriptInteger: public Expression {
private:
int val;
public:
ScriptInteger(int i);
ScriptInteger(char* c);
string toString() ;
unique_ptr<Expression> eval();
unique_ptr<Expression> add(Expression& e);
unique_ptr<Expression> index(Expression& e);
~ScriptInteger();
};
class ScriptString : public Expression {
private:
string val;
public:
ScriptString(const char* c);
ScriptString(const string &c);
string toString() ;
unique_ptr<Expression> eval();
unique_ptr<Expression> add(Expression& e);
unique_ptr<Expression> index(Expression& e);
~ScriptString();
};
class BinaryOperator : public Expression {
public:
unique_ptr<Expression> add(Expression& e);
unique_ptr<Expression> index(Expression& e);
string toString() ;
};
class Assign : public BinaryOperator {
private:
unique_ptr<Expression> lval;
unique_ptr<Expression> rval;
public:
Assign(Expression* lval, Expression* rval);
unique_ptr<Expression> eval();
~Assign();
};
class Add : public BinaryOperator {
private:
unique_ptr<Expression> lval;
unique_ptr<Expression> rval;
public:
Add(Expression* larg, Expression* rarg);
unique_ptr<Expression> eval();
~Add();
};
class Index : public BinaryOperator {
private:
unique_ptr<Expression> lval;
unique_ptr<Expression> rval;
public:
Index(Expression* larg, Expression* rarg);
unique_ptr<Expression> eval();
~Index();
};
class Statement {
private:
int lineNo;
public:
friend ostream& operator << (ostream& os, Statement& e);
void setLineNo(int line);
void wrapException(std::exception &e);
virtual void execute(ostream & os)=0;
};
class ExpressionStatement: public Statement {
private:
unique_ptr<Expression> expr;
public:
ExpressionStatement(Expression * e);
void execute(ostream & os);
};
class VardeclStatement: public Statement {
private:
string name;
unique_ptr<Expression> expr;
shared_ptr<SymbolTable> table;
public:
VardeclStatement(shared_ptr<SymbolTable> table, string name, Expression * e);
VardeclStatement(shared_ptr<SymbolTable> table, string name);
void execute(ostream & os);
};
class StatementBlock : public Statement {
private:
list<unique_ptr<Statement>> stmt_list;
public:
void execute(ostream & os);
void addStatement(Statement * stmt);
};
class Script : public StatementBlock {
};
class IfStatement : public Statement {
private:
unique_ptr<Expression> cond;
unique_ptr<Statement> trueStmt;
unique_ptr<Statement> falseStmt;
public:
IfStatement(Expression * cond, Statement * trueStmt);
IfStatement(Expression * cond, Statement * trueStmt, Statement * falseStmt);
void execute(ostream & os);
};
class PrintStatement : public Statement {
private:
unique_ptr<Expression> val;
public:
PrintStatement(Expression * val);
void execute(ostream & os);
};
#endif