main
Alpha Chen 2 years ago
parent f9da923296
commit 02bea3faea

@ -22,6 +22,36 @@ module Lox
nil
end
def visit_expr(stmt)
resolve(stmt.expr)
nil
end
def visit_function(stmt)
declare(stmt.name)
define(stmt.name)
resolve_function(stmt)
nil
end
def visit_if(stmt)
resolve(stmt.condition)
resolve(stmt.then)
resolve(stmt.else) if stmt.else
nil
end
def visit_print(stmt)
resolve(stmt.expr)
nil
end
def visit_return(stmt)
resolve(stmt.value) if stmt.value
nil
end
def visit_var(stmt)
declare(stmt.name)
resolve(stmt.initializer) if stmt.initializer
@ -29,6 +59,12 @@ module Lox
nil
end
def visit_while(stmt)
resolve(stmt.condition)
resolve(stmt.body)
nil
end
def visit_variable(expr)
if !@scopes.empty? && @scopes.last[expr.name.lexeme] == false
raise ResolverError.new(expr.name, "Can't read local variable in its own initializer.")
@ -44,11 +80,33 @@ module Lox
nil
end
def visit_function(stmt)
declare(stmt.name)
define(stmt.name)
def visit_binary(expr)
resolve(expr.left)
resolve(expr.right)
nil
end
resolve_function(stmt)
def visit_call(expr)
resolve(expr.callee, *expr.args)
nil
end
def visit_grouping(expr)
resolve(expr.expr)
nil
end
def visit_literal(expr)
nil
end
def visit_logical(expr)
resolve(expr.left, expr.right)
nil
end
def visit_unary(expr)
resolve(expr.right)
nil
end

Loading…
Cancel
Save