Class: Layo::Interpreter
- Inherits:
-
BaseInterpreter
- Object
- BaseInterpreter
- Layo::Interpreter
- Defined in:
- lib/layo/interpreter.rb
Instance Attribute Summary
Attributes inherited from BaseInterpreter
Instance Method Summary collapse
-
#eval_function_stmt(stmt) ⇒ Object
Don’t do anything because function table is already ready.
- #eval_program(program) ⇒ Object
-
#interpret(program) ⇒ Object
Interprets program given as an AST node.
Methods inherited from BaseInterpreter
#call_func, #cast, #create_variable_table, #eval_assignment_stmt, #eval_binary_expr, #eval_block, #eval_break_stmt, #eval_cast_expr, #eval_cast_stmt, #eval_condition_stmt, #eval_constant_expr, #eval_declaration_stmt, #eval_expr, #eval_expression_stmt, #eval_function_expr, #eval_input_stmt, #eval_loop_stmt, #eval_nary_expr, #eval_print_stmt, #eval_return_stmt, #eval_switch_stmt, #eval_unary_expr, #eval_variable_expr, #init_tables, #initialize, #interpolate_string, #with_guard
Constructor Details
This class inherits a constructor from Layo::BaseInterpreter
Instance Method Details
#eval_function_stmt(stmt) ⇒ Object
Don’t do anything because function table is already ready
23 |
# File 'lib/layo/interpreter.rb', line 23 def eval_function_stmt(stmt); end |
#eval_program(program) ⇒ Object
18 19 20 |
# File 'lib/layo/interpreter.rb', line 18 def eval_program(program) with_guard { eval_block(program.block) } end |
#interpret(program) ⇒ Object
Interprets program given as an AST node
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/layo/interpreter.rb', line 4 def interpret(program) # We should gather all function definitions along with their bodies # beforehand so we could call them wherever a call appears init_tables program.block.each do |statement| if statement.type == 'function' @functions[statement.name] = { args: statement.args, block: statement.block } end end eval_program(program) end |