-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerm.java
More file actions
46 lines (42 loc) · 1.45 KB
/
Term.java
File metadata and controls
46 lines (42 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
class Term{
Factor ft;
Term tr;
int flag = 0;
void parse(Scanner s){
if(s.currentToken() != Core.ID && s.currentToken() != Core.CONST && s.currentToken() != Core.LPAREN){
System.out.println("Error: Expected ID, CONST, or LPAREN Token. Got: " + s.currentToken());
System.exit(1);
}
ft = new Factor();
ft.parse(s);
if(s.currentToken() == Core.MULTIPLY){
flag = 1;
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. Got: " + s.currentToken());
System.exit(1);
}
tr = new Term();
tr.parse(s);
}else if( s.currentToken() == Core.DIVIDE){
flag = 2;
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. Got: " + s.currentToken());
System.exit(1);
}
tr = new Term();
tr.parse(s);
}
}
void print(){
ft.print();
if(flag == 1){
System.out.println("*");
tr.print();
}else if(flag == 2){
System.out.println("/");
tr.print();
}
}
}