ifStatement method

Stmt ifStatement()

Implementation

Stmt ifStatement() {
  consume(TokenType.LEFT_PAREN, "Expect '(' after 'if'.");
  Expr condition = expression();
  consume(TokenType.RIGHT_PAREN, "Expect ')' after if condition.");
  Stmt thenBranch = statement();
  Stmt? elseBranch;
  if (match([TokenType.ELSE])) {
    elseBranch = statement();
  }
  return If(condition, thenBranch, elseBranch);
}