-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOut.java
More file actions
45 lines (41 loc) · 1.39 KB
/
Out.java
File metadata and controls
45 lines (41 loc) · 1.39 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
class Out{
Expr ex;
void parse(Scanner s){
//Checks if Current Token is OUT Token, NEXT TOKEN
if(s.currentToken()!=Core.OUT){
System.out.println("ERROR: Expected OUT Token");
System.exit(1);
}
s.nextToken();
//Checks if Current Token is LPAREN, NEXT TOKEN
if(s.currentToken()!=Core.LPAREN){
System.out.println("ERROR: Expected LPAREN Token");
System.exit(1);
}
s.nextToken();
//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);
//Checks if token is RPAREN, NEXT TOKEN
if(s.currentToken()!=Core.RPAREN){
System.out.println("ERROR: Expected RPAREN Token");
System.exit(1);
}
s.nextToken();
//Checks if Token is Semicolon, NEXT TOKEN
if(s.currentToken()!= Core.SEMICOLON){
System.out.println("Error: Expeceted SEMICOLON Token");
System.exit(1);
}
s.nextToken();
}
void print(){
System.out.println("out(");
ex.print();
System.out.print(");");
}
}