-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
56 lines (51 loc) · 1.18 KB
/
Copy pathProgram.java
File metadata and controls
56 lines (51 loc) · 1.18 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
import java.util.*;
class Program {
DeclSeq ds;
StmtSeq ss;
void parse() {
Parser.expectedToken(Core.PROGRAM);
Parser.scanner.nextToken();
if (Parser.scanner.currentToken() != Core.BEGIN) {
ds = new DeclSeq();
ds.parse();
}
Parser.expectedToken(Core.BEGIN);
Parser.scanner.nextToken();
ss = new StmtSeq();
ss.parse();
Parser.expectedToken(Core.END);
Parser.scanner.nextToken();
Parser.expectedToken(Core.EOF);
}
void semantic() {
Parser.funcNames = new ArrayList<String>();
Parser.scopes = new Stack<ArrayList<String>>();
Parser.scopes.push(new ArrayList<String>());
if (ds != null) {
ds.semantic();
}
Parser.scopes.push(new ArrayList<String>());
ss.semantic();
Parser.scopes.pop();
}
void print() {
System.out.println("program");
if (ds != null) {
ds.print(1);
}
System.out.println("begin");
ss.print(1);
System.out.println("end");
}
void execute() {
// Initialize the data structures in Executor
Executor.initExecutor();
if (ds != null) {
ds.execute();
}
//Add a frame for the local scope
Executor.pushFrame();
ss.execute();
Executor.popFrame();
}
}