-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop.java
More file actions
48 lines (43 loc) · 1008 Bytes
/
Copy pathLoop.java
File metadata and controls
48 lines (43 loc) · 1008 Bytes
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
import java.util.*;
class Loop implements Stmt {
Cond cond;
StmtSeq ss;
public void parse() {
Parser.scanner.nextToken();
cond = new Cond();;
cond.parse();
Parser.expectedToken(Core.BEGIN);
Parser.scanner.nextToken();
ss = new StmtSeq();
ss.parse();
Parser.expectedToken(Core.ENDWHILE);
Parser.scanner.nextToken();
}
public void semantic() {
cond.semantic();
Parser.scopes.push(new ArrayList<String>());
ss.semantic();
Parser.scopes.pop();
}
public void print(int indent) {
for (int i=0; i<indent; i++) {
System.out.print("\t");
}
System.out.print("while ");
cond.print();
System.out.println(" begin");
ss.print(indent+1);
for (int i=0; i<indent; i++) {
System.out.print("\t");
}
System.out.println("endwhile");
}
public void execute() {
while (cond.execute()) {
//Add a map for the new local scope, pop when done
Executor.pushScope();
ss.execute();
Executor.popScope();
}
}
}