-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop.java
More file actions
44 lines (40 loc) · 1.54 KB
/
Loop.java
File metadata and controls
44 lines (40 loc) · 1.54 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
class Loop{
Cond cd;
StmtSeq ss;
void parse(Scanner s){
if(s.currentToken()!= Core.WHILE){
System.out.println("ERROR: Expected WHILE Token. Got: "+ s.currentToken());
System.exit(1);
}
s.nextToken();
if(s.currentToken() != Core.ID && s.currentToken() != Core.CONST && s.currentToken() != Core.LPAREN && s.currentToken()!= Core.NOT){
System.out.println("Error: Expected ID, CONST, NOT, or LPAREN Token. Got: " + s.currentToken());
System.exit(1);
}
cd = new Cond();
cd.parse(s);
if(s.currentToken() != Core.DO){
System.out.println("ERROR: Expected DO Token. Got: "+ s.currentToken());
System.exit(1);
}
s.nextToken();
if(s.currentToken() != Core.ID && s.currentToken() != Core.IF && s.currentToken() != Core.WHILE && s.currentToken() != Core.OUT && s.currentToken() != Core.IN && s.currentToken() != Core.INTEGER && s.currentToken() != Core.ARRAY ){
System.out.println("Error: Expected ID, IF, WHILE, OUT, IN, INTEGER, or ARRAY Token");
System.exit(1);
}
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();
}
void print(){
System.out.println("while ");
cd.print();
System.out.print(" do ");
ss.print();
System.out.print(" end");
}
}