-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStmtSeq.java
More file actions
61 lines (55 loc) · 1.92 KB
/
Copy pathStmtSeq.java
File metadata and controls
61 lines (55 loc) · 1.92 KB
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
class StmtSeq {
Stmt stmt;
StmtSeq ss;
void parse() {
if (Parser.scanner.currentToken() == Core.ID) {
this.stmt = new Assign();
} else if (Parser.scanner.currentToken() == Core.INPUT) {
this.stmt = new Input();
} else if (Parser.scanner.currentToken() == Core.OUTPUT) {
this.stmt = new Output();
} else if (Parser.scanner.currentToken() == Core.IF) {
this.stmt = new If();
} else if (Parser.scanner.currentToken() == Core.WHILE) {
this.stmt = new Loop();
} else if (Parser.scanner.currentToken() == Core.INT) {
this.stmt = new Decl();
} else if (Parser.scanner.currentToken() == Core.BEGIN) {
this.stmt = new FuncCall();
} else if (Parser.scanner.currentToken() == Core.DEFINE) {
this.stmt = new NewDecl();
}
else {
System.out.println("ERROR: Bad start to statement: "
+ Parser.scanner.currentToken());
System.exit(0);
}
this.stmt.parse();
if ((Parser.scanner.currentToken() != Core.END)
&& (Parser.scanner.currentToken() != Core.ENDIF)
&& (Parser.scanner.currentToken() != Core.ENDWHILE)
&& (Parser.scanner.currentToken() != Core.ELSE)
&& (Parser.scanner.currentToken() != Core.ENDFUNC)) {
this.ss = new StmtSeq();
this.ss.parse();
}
}
void semantic() {
this.stmt.semantic();
if (this.ss != null) {
this.ss.semantic();
}
}
void print(int indent) {
this.stmt.print(indent);
if (this.ss != null) {
this.ss.print(indent);
}
}
void execute() {
this.stmt.execute();
if (this.ss != null) {
this.ss.execute();
}
}
}