-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmpr.java
More file actions
41 lines (37 loc) · 1.16 KB
/
Cmpr.java
File metadata and controls
41 lines (37 loc) · 1.16 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
class Cmpr{
Expr ex;
Expr ex2;
int flag = 0;
void parse(Scanner s){
//Checks if token is beginning of an expression, if it is, parses the expression
if(s.currentToken() != Core.ID && s.currentToken() != Core.CONST && s.currentToken() != Core.LPAREN){
System.out.println("Error: Expected ID, CONST, or LPAREN Token");
System.exit(1);
}
ex = new Expr();
ex.parse(s);
if(s.currentToken() == Core.EQUAL){
flag = 0;
}else if(s.currentToken() == Core.LESS){
flag = 1;
}else{
System.out.println("Error: Expected EQUAL or LESS Token");
}
s.nextToken();
if(s.currentToken() != Core.ID && s.currentToken() != Core.CONST && s.currentToken() != Core.LPAREN){
System.out.println("Error: Expected ID, CONST, or LPAREN Token");
System.exit(1);
}
ex2 = new Expr();
ex2.parse(s);
}
void print(){
ex.print();
if(flag == 0){
System.out.print("=");
}else if(flag == 1){
System.out.print("<");
}
ex2.print();
}
}