diff options
Diffstat (limited to 'src/ast/nodes/IfNode.java')
-rw-r--r-- | src/ast/nodes/IfNode.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java index ca42b7a..fd878f8 100644 --- a/src/ast/nodes/IfNode.java +++ b/src/ast/nodes/IfNode.java @@ -34,7 +34,6 @@ public class IfNode implements Node { return errors; } - // FIXME: fix the if statement @Override public Type typeCheck() { if (guard.typeCheck() instanceof BoolType) { @@ -78,14 +77,26 @@ public class IfNode implements Node { } @Override - public String toPrint(String prefix) { - String str = prefix + "If\n" + guard.toPrint(prefix + " ") + thenBranch.toPrint(prefix + " "); + public String printAST(String prefix) { + String str = prefix + "If\n" + guard.printAST(prefix + " ") + thenBranch.printAST(prefix + " "); if (elseBranch != null) { - str += elseBranch.toPrint(prefix + " "); + str += elseBranch.printAST(prefix + " "); } return str; } + @Override + public String toPrint(String prefix) { + String str = prefix + "if "; + str += guard.toPrint("") + ":\n"; + str += thenBranch.toPrint(prefix + "\t") + "\n"; + if (elseBranch != null) { + str += prefix + "else:\n"; + str += elseBranch.toPrint(prefix + "\t") + "\n"; + } + return str; + } + } |