-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTNot.java
More file actions
34 lines (26 loc) · 814 Bytes
/
Copy pathASTNot.java
File metadata and controls
34 lines (26 loc) · 814 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
public class ASTNot implements ASTNode {
ASTNode exp;
public ASTNot(ASTNode e)
{
exp = e;
}
@Override
public IValue eval(Environment<IValue> e) throws InterpreterError {
IValue v0 = exp.eval(e);
if (v0 instanceof VBool) {
return new VBool(!((VBool)v0).getval());
} else {
throw new InterpreterError("illegal type to not operator");
}
}
public ASTType typecheck(Environment<ASTType> e) throws TypeCheckError, InterpreterError {
ASTType t = exp.typecheck(e);
if (!(t instanceof ASTTBool))
throw new TypeCheckError("~: arg type not bool");
return ASTTBool.tbool;
}
@Override
public boolean isFreeOutsideLambda(String id) {
return exp.isFreeOutsideLambda(id);
}
}