|
|
@ -50,6 +50,7 @@ module Lox
|
|
|
|
return for_stmt if match?(:FOR)
|
|
|
|
return for_stmt if match?(:FOR)
|
|
|
|
return if_stmt if match?(:IF)
|
|
|
|
return if_stmt if match?(:IF)
|
|
|
|
return print if match?(:PRINT)
|
|
|
|
return print if match?(:PRINT)
|
|
|
|
|
|
|
|
return return_stmt if match?(:RETURN)
|
|
|
|
return while_stmt if match?(:WHILE)
|
|
|
|
return while_stmt if match?(:WHILE)
|
|
|
|
return Stmt::Block.new(block) if match?(:LEFT_BRACE)
|
|
|
|
return Stmt::Block.new(block) if match?(:LEFT_BRACE)
|
|
|
|
|
|
|
|
|
|
|
@ -111,6 +112,13 @@ module Lox
|
|
|
|
Stmt::Print.new(value)
|
|
|
|
Stmt::Print.new(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def return_stmt
|
|
|
|
|
|
|
|
keyword = prev
|
|
|
|
|
|
|
|
value = check?(:SEMICOLON) ? nil : expression
|
|
|
|
|
|
|
|
consume!(:SEMICOLON, "Expect ';' after return value.")
|
|
|
|
|
|
|
|
Stmt::Return.new(keyword, value)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def expression_stmt
|
|
|
|
def expression_stmt
|
|
|
|
value = expression
|
|
|
|
value = expression
|
|
|
|
consume!(:SEMICOLON, "Expect ';' after value.")
|
|
|
|
consume!(:SEMICOLON, "Expect ';' after value.")
|
|
|
|