-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatements.h
124 lines (102 loc) · 2.38 KB
/
statements.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 __STATEMENTS_H
#define __STATEMENTS_H
#include <string.h>
#include "ast.h"
#include "expressions.h"
#include "boolExpressions.h"
#include "case.h"
class Stmt : public ASTnode
{
protected:
Stmt* next; // used to link together statements in the same block
Stmt() : next(NULL) {};
public:
virtual void genStmt() = 0; // abstract class - every subclass should override and implement this fun
Stmt* getNext() const { return next; };
void setNext(Stmt* next) { this->next = next; };
};
class ReadStmt : public Stmt
{
private:
IdNode* id; // note: IdNode is subclass of Exp but this IdNode is not really an expression
int line; // line in source code
public:
ReadStmt(IdNode* id, int line);
void genStmt(); // override
};
class AssignStmt : public Stmt
{
private:
IdNode* lhs; // left hand side
Exp* rhs; // right hand side
int line; // line in source code
public:
AssignStmt(IdNode* lhs, Exp* rhs, int line);
void genStmt(); // override
};
class RepeatStmt : public Stmt
{
private:
Exp* expression; // should be int - num times for iteration
Stmt* repeatStmt;
int line; // line in source code
public:
RepeatStmt(Exp* expression, Stmt* repeatStmt, int line);
void genStmt(); // override
};
class IfStmt : public Stmt
{
private:
BoolExp* condition;
Stmt* thenStmt;
Stmt* elseStmt;
public:
IfStmt(BoolExp* condition, Stmt* thenStmt, Stmt* elseStmt);
void genStmt(); // override
};
class WhileStmt : public Stmt
{
private:
BoolExp* condition;
Stmt* body;
public:
WhileStmt(BoolExp* condition, Stmt* body);
void genStmt(); // override
};
// a block contains a list of statements. For now -- no declarations in a block
class Block : public Stmt
{
private:
Stmt* stmtlist; // pointer to the first statement. each statement points to the next stmt
public:
Block(Stmt* stmtlist);
void genStmt(); // override
};
class BreakStmt : public Stmt
{
private:
int line; // source line
public:
BreakStmt(int line);
void genStmt(); // override
};
class ContinueStmt : public Stmt
{
private:
int line; // source line
public:
ContinueStmt(int line);
void genStmt(); // override
};
class SwitchStmt : public Stmt
{
private:
Exp* exp;
Case* caselist; // pointer to first case in caselist
Stmt* default_stmt;
int line; // source line of switch token
public:
SwitchStmt(Exp* exp, Case* caselist, Stmt* default_stmt, int line);
void genStmt(); // override
};
#endif