-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.h
122 lines (101 loc) · 2.79 KB
/
statement.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
#ifndef STATEMENT_H
#define STATEMENT_H
#include <QDebug>
#include <QString>
#include "exceptions.h"
#include "expression.h"
#include "runtime.h"
#include "utils.h"
class Statement {
private:
QString name;
public:
Exception* error = nullptr;
Statement();
Statement(QString n);
static Statement* parse(const QString statement);
virtual void execute(Runtime* context) const;
virtual const QString ast() const;
virtual ~Statement();
};
class RemarkStatement: public Statement {
private:
QString body;
public:
RemarkStatement(const QString b): body(b) {
}
void execute(Runtime* context) const override;
const QString ast() const override;
};
class LetStatement: public Statement {
private:
const Expression* expression;
public:
LetStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
~LetStatement();
};
class PrintStatement: public Statement {
private:
const Expression* expression;
public:
PrintStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
~PrintStatement();
};
class PrintfStatement: public Statement {
private:
QString formatString;
QList<const Expression*> args;
const QString pattern = "{}";
QList<QString> getArguments(const QString body) const;
public:
PrintfStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
~PrintfStatement();
};
class InputStatement: public Statement {
protected:
QString identifier;
public:
InputStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
};
class InputsStatement: public InputStatement {
public:
InputsStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
};
class GotoStatement: public Statement {
private:
const QString destination;
public:
GotoStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
QString getDestination() const;
};
class IfStatement: public Statement {
private:
QChar conditionOp;
const Expression *lhs, *rhs;
const GotoStatement* gotoStmt;
// Parse condition, set condition operator, and return index of operator
int parseCondition(const QString condition);
public:
IfStatement(const QString body);
void execute(Runtime* context) const override;
const QString ast() const override;
~IfStatement();
};
class EndStatement: public Statement {
public:
void execute(Runtime* context) const override;
const QString ast() const override;
};
#endif // STATEMENT_H