-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFunCall.java
More file actions
43 lines (39 loc) · 1.09 KB
/
FunCall.java
File metadata and controls
43 lines (39 loc) · 1.09 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
import java.util.ArrayList;
class FunCall extends ExampleToken implements Token
{
String id;
Params params;
FullType datum;
public FunCall(String i)
{
id = i;
params = null;
}
public FunCall(String i, Params p)
{
id = i;
params = p;
}
public String toString(int t)
{
return id + "(" + (params != null ? params.toString(t) : "") + ")";
}
public FullType typeCheck() throws ExampleException
{
FullType thisType = table.getType(id);
datum = thisType;
if (thisType == null || !thisType.isFunction)
throw new ExampleException("Error: " + id + " not declared as function");
ArrayList<FullType> ps = params.typeCheck();
if (thisType.args.size() != ps.size())
throw new ExampleException("Error: wrong number of arguments");
for (int i = 0; i < thisType.args.size(); ++i)
if (!thisType.args.get(i).getValue().isAble(ps.get(i)))
throw new ExampleException("Error: bad param");
return new FullType(thisType.baseType);
}
public Object execute()
{
return ((Decl)(datum.value)).call(params.execute());
}
}