Skip to content

Commit

Permalink
AST toString fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartel committed Mar 18, 2013
1 parent cf12368 commit 847e711
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/minicompiler/ast/IfStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public IfStatement(Expr condition, Statement thenClause) {
public void accept(AstVisitor v) {
v.visit(this);
}

public boolean hasElseClause() {
return !(elseClause instanceof EmptyStatement);
}

@Override
public boolean equals(Object obj) {
Expand All @@ -41,10 +45,10 @@ public int hashCode() {

@Override
public String toString() {
if (elseClause instanceof EmptyStatement) {
return "if (" + condition + ") " + thenClause;
if (hasElseClause()) {
return "if " + condition + " then " + thenClause + " else " + elseClause;
} else {
return "if (" + condition + ") " + thenClause + " else " + elseClause;
return "if " + condition + " then " + thenClause;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/minicompiler/ast/WhileLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public int hashCode() {

@Override
public String toString() {
return "while (" + head + ") { " + body + " }";
return "while " + head + " do " + body;
}
}

0 comments on commit 847e711

Please sign in to comment.