-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCond.java
More file actions
50 lines (48 loc) · 1.45 KB
/
Cond.java
File metadata and controls
50 lines (48 loc) · 1.45 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
class Cond{
Cmpr cr;
Cond cd;
int flag = 0;
void parse(Scanner s){
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);
}
if(s.currentToken() == Core.ID || s.currentToken() == Core.CONST || s.currentToken() == Core.LPAREN){
flag = 0;
cr = new Cmpr();
cr.parse(s);
if(s.currentToken() == Core.OR){
flag = 2;
s.nextToken();
cd = new Cond();
cd.parse(s);
}else if(s.currentToken() == Core.AND){
flag = 3;
s.nextToken();
cd = new Cond();
cd.parse(s);
}
}else if(s.currentToken() == Core.NOT){
flag = 1;
s.nextToken();
cd = new Cond();
cd.parse(s);
}
}
void print(){
if(flag == 0){
cr.print();
}else if(flag == 1){
System.out.print("not ");
cd.print();
}else if(flag == 2){
cr.print();
System.out.print(" or ");
cd.print();
}else if(flag == 3){
cr.print();
System.out.print(" and ");
cd.print();
}
}
}