A naive implmentation of Boolean types and nil node has been added
This commit is contained in:
parent
e3b6a054b4
commit
709346311a
|
@ -5,7 +5,7 @@ public class FalseNode extends Node {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object eval(Scope scope) {
|
public Object eval(Scope scope) {
|
||||||
return false;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class IfSpecialForm extends SpecialForm {
|
||||||
@Override
|
@Override
|
||||||
public Object eval(final Scope scope) {
|
public Object eval(final Scope scope) {
|
||||||
Object result = this.pred.eval(scope);
|
Object result = this.pred.eval(scope);
|
||||||
if (result == null) {
|
if (result == null || (result instanceof Boolean && (Boolean) result == false)) {
|
||||||
return this.elseNode.eval(scope);
|
return this.elseNode.eval(scope);
|
||||||
}
|
}
|
||||||
return this.ifNode.eval(scope);
|
return this.ifNode.eval(scope);
|
||||||
|
|
|
@ -43,7 +43,12 @@ public class Main {
|
||||||
|
|
||||||
if (result != ListNode.EMPTY) {
|
if (result != ListNode.EMPTY) {
|
||||||
System.out.print(";; ");
|
System.out.print(";; ");
|
||||||
System.out.println(result.toString());
|
if (result == null) {
|
||||||
|
System.out.println("nil");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println(result.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ public class NilNode extends Node {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object eval(Scope scope) {
|
public Object eval(Scope scope) {
|
||||||
return this;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -83,7 +83,17 @@ public class Reader {
|
||||||
str = str + (char) ch;
|
str = str + (char) ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SymbolNode(str);
|
switch(str) {
|
||||||
|
case "true":
|
||||||
|
return new TrueNode();
|
||||||
|
case "false":
|
||||||
|
return new FalseNode();
|
||||||
|
case "nil":
|
||||||
|
return new NilNode();
|
||||||
|
default:
|
||||||
|
return new SymbolNode(str);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Node readNumber(PushbackReader inputStream) throws IOException {
|
private static Node readNumber(PushbackReader inputStream) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue