-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcedure.java
More file actions
62 lines (53 loc) · 1.51 KB
/
Procedure.java
File metadata and controls
62 lines (53 loc) · 1.51 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
62
class Procedure{
String name;
DeclSeq ds;
StmtSeq ss;
void parse(Scanner s){
if(s.currentToken() != Core.PROCEDURE){
System.out.println("Error: Expected Procedure Token");
System.exit(1);
}
s.nextToken();
if(s.currentToken() != Core.ID){
System.out.println("Error: Expeceted ID Token");
System.exit(1);
}
name = s.getId();
s.nextToken();
if(s.currentToken() != Core.IS){
System.out.println("Error: Expected IS Token");
System.exit(1);
}
s.nextToken();
if(s.currentToken() != Core.BEGIN){
ds = new DeclSeq();
ds.parse(s);
}
if(s.currentToken() != Core.BEGIN){
System.out.println("Error: Expected BEGIN Token");
System.exit(1);
}
s.nextToken();
ss = new StmtSeq();
ss.parse(s);
if(s.currentToken() != Core.END){
System.out.println("Error: Expected END Token. Got: " + s.currentToken());
System.exit(1);
}
s.nextToken();
if(s.currentToken() != Core.EOS){
System.out.println("Error: Expected EOS Token");
System.exit(1);
}
s.nextToken();
}
void print(){
System.out.println("procedure " + name + " is ");
if(ds != null){
ds.print();
}
System.out.println("begin");
ss.print();
System.out.println("end");
}
}