-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.h
83 lines (73 loc) · 2.17 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
#pragma once
#include "expression.h"
enum StatementType {
STATEMENT_REM,
STATEMENT_LET,
STATEMENT_PRINT,
STATEMENT_INPUT,
STATEMENT_GOTO,
STATEMENT_IF,
STATEMENT_END
};
struct Statement {
StatementType type;
Statement(StatementType type) : type(type) {}
virtual ~Statement() {}
virtual QStringList toHTML() const = 0;
virtual void zeroOut() = 0;
};
struct RemStatement : Statement {
QString comment;
RemStatement(const QString &comment) : Statement(STATEMENT_REM), comment(comment) {}
QStringList toHTML() const;
void zeroOut() {}
};
struct LetStatement : Statement {
QString variable;
Expression *expression;
size_t count;
LetStatement(const QString &variable, Expression *expression)
: Statement(STATEMENT_LET), variable(variable), expression(expression), count(0) {}
~LetStatement() { delete expression; }
QStringList toHTML() const;
void zeroOut() { count = 0; }
};
struct PrintStatement : Statement {
Expression *expression;
size_t count;
PrintStatement(Expression *expression) : Statement(STATEMENT_PRINT), expression(expression), count(0) {}
~PrintStatement() { delete expression; }
QStringList toHTML() const;
void zeroOut() { count = 0; }
};
struct InputStatement : Statement {
QString variable;
size_t count;
InputStatement(const QString &variable) : Statement(STATEMENT_INPUT), variable(variable), count(0) {}
QStringList toHTML() const;
void zeroOut() { count = 0; }
};
struct GotoStatement : Statement {
size_t destination;
size_t count;
GotoStatement(size_t destination) : Statement(STATEMENT_GOTO), destination(destination), count(0) {}
QStringList toHTML() const;
void zeroOut() { count = 0; }
};
struct IfStatement : Statement {
Expression *condition;
size_t destination;
size_t ifCount;
size_t thenCount;
IfStatement(Expression *condition, size_t destination)
: Statement(STATEMENT_IF), condition(condition), destination(destination), ifCount(0), thenCount(0) {}
~IfStatement() { delete condition; }
QStringList toHTML() const;
void zeroOut() { ifCount = thenCount = 0; }
};
struct EndStatement : Statement {
size_t count;
EndStatement() : Statement(STATEMENT_END), count(0) {}
QStringList toHTML() const;
void zeroOut() { count = 0; }
};