blob: ce4113c21a2275e92d82d7a47585563dc46cc832 (
plain)
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
51
52
53
54
|
package minijava.symboltable;
public class MPrimaryExpr extends MType {
/**
* f0 -> IntegerLiteral()
* | TrueLiteral()
* | FalseLiteral()
* | Identifier()
* | ThisExpression()
* | ArrayAllocationExpression()
* | AllocationExpression()
* | NotExpression()
* | BracketExpression()
*/
public enum E_type {
Int, True, False, Id, This, ArrayAlloc, Alloc, Not, Braket;
}
public E_type e_type;
public int i_val; // int
public MIdentifier e_id = null; // Id, ArrayAlloc, Alloc
public MExpression e_exp = null; // ArrayAlloc, Not, Braket
public int toInt() {
return i_val;
}
public boolean toBool() {
if (e_type==E_type.True) {
return true;
} else if (e_type==E_type.False) {
return false;
} else {
throw new IllegalArgumentException("invalid call to toBool()");
}
}
public void printPrimExpr(int spaces) {
System.err.print(OutputFormat.spaces(spaces));
switch (e_type) {
case Int:
System.err.print(i_val);
break;
case True:
case False:
System.err.print(this.toBool());
break;
case Id:
System.err.print(e_id.getName());
break;
}
}
}
|