-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.h
124 lines (106 loc) · 2.49 KB
/
interpreter.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
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <forward_list>
namespace Interpreter
{
class Expression
{
public:
virtual int Evaluate() = 0;
};
class Val : public Expression
{
public:
const int val;
Val(int val);
virtual int Evaluate();
};
class Id : public Expression
{
public:
const char* const name;
Id(const char *name);
virtual int Evaluate();
void Assign(int val);
};
class Op
{
public:
const char* const glyph;
Op(const char *glyph);
};
class ExpressionNode : public Expression
{
private:
Expression *left;
Expression *right;
Op *op;
public:
ExpressionNode(Expression *left, Expression *right, Op* op);
virtual int Evaluate();
};
class Statement
{
public:
virtual void Execute() = 0;
};
class Statements : public Statement
{
private:
Statement *statement;
Statements *childStatements;
public:
Statements(Statement *statement, Statements *childStatements);
virtual void Execute();
};
class Assignment : public Statement
{
private:
Id *id;
Expression *right;
public:
Assignment(Id *id, Expression* right);
virtual void Execute();
};
class Conditional : public Statement
{
private:
Expression *condition;
Statement *statement;
public:
Conditional(Expression *condition, Statement *statement);
virtual void Execute();
};
class Print : public Statement
{
private:
Expression *expr;
public:
Print(Expression *expr);
virtual void Execute();
};
struct ProcedureCallArgument
{
ProcedureCallArgument(Expression* expression);
Expression* const expression;
};
class ProcedureDeclaration : public Statement
{
public:
Id* const id;
Statements* const statements;
std::forward_list<Id*>* const arguments;
ProcedureDeclaration(Id *id, std::forward_list<Id*>* arguments, Statements *statements);
virtual void Execute();
};
class ProcedureCall : public Statement
{
private:
std::forward_list<ProcedureCallArgument*>* arguments;
Id* id;
public:
ProcedureCall(Id *id, std::forward_list<ProcedureCallArgument*>* arguments);
virtual void Execute();
};
}
#endif