Skip to content

Commit

Permalink
Update challenge visitors to accept logical exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
nop committed Aug 16, 2023
1 parent a1391d1 commit 87c5486
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/craftinginterpreters/lox/AstPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public String visitLiteralExpr(final Expr.Literal expr) {
return expr.value.toString();
}

@Override
public String visitLogicalExpr(Expr.Logical expr) {
return parenthesize(expr.operator.lexeme, expr.left, expr.right);
}

@Override
public String visitUnaryExpr(final Expr.Unary expr) {
return parenthesize(expr.operator.lexeme, expr.right);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/craftinginterpreters/lox/RpnPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public String visitLiteralExpr(Expr.Literal expr) {
return expr.value.toString();
}

@Override
public String visitLogicalExpr(Expr.Logical expr) {
return expr.left.accept(this) + " " + expr.right.accept(this) + " " + expr.operator.lexeme;
}

@Override
public String visitUnaryExpr(Expr.Unary expr) {
return expr.right.accept(this) + expr.operator.lexeme;
Expand Down

0 comments on commit 87c5486

Please sign in to comment.