-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAsn.java
More file actions
40 lines (36 loc) · 926 Bytes
/
Asn.java
File metadata and controls
40 lines (36 loc) · 926 Bytes
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
import java.util.ArrayList;
class Asn extends Stmt implements Token
{
String id;
Expr expr;
FullType datum;
public Asn(String i, Expr e)
{
id = i;
expr = e;
}
public String toString(int t)
{
return T(t) + id + " = " + expr.toString(t) + ";" + super.toString(t);
}
public void typeCheck() throws ExampleException
{
FullType thisType = table.getType(id);
datum = thisType;
if (thisType == null)
throw new ExampleException("Error: " + id + " not declared");
FullType exprType = expr.typeCheck();
if (!thisType.isAble(exprType))
throw new ExampleException("Error: incompatible types");
}
public void execute()
{
Object o = expr.execute();
if (o instanceof Integer)
datum.value = new Integer((Integer)o);
if (o instanceof Float)
datum.value = new Float((Float)o);
if (o instanceof ArrayList)
datum.value = o;
}
}