class Kaze::Interpreter

Overview

Interpreter to compute expressions and statements.

Included Modules

Defined in:

interpreter.cr

Constructors

Instance Method Summary

Instance methods inherited from module Kaze::Stmt::Visitor

visit_block_stmt(stmt : Block) : VG visit_block_stmt, visit_break_stmt(stmt : Break) : VG visit_break_stmt, visit_class_stmt(stmt : Class) : VG visit_class_stmt, visit_expression_stmt(stmt : Expression) : VG visit_expression_stmt, visit_function_stmt(stmt : Function) : VG visit_function_stmt, visit_if_stmt(stmt : If) : VG visit_if_stmt, visit_return_stmt(stmt : Return) : VG visit_return_stmt, visit_var_stmt(stmt : Var) : VG visit_var_stmt, visit_while_stmt(stmt : While) : VG visit_while_stmt

Instance methods inherited from module Kaze::Expr::Visitor

visit_assign_expr(expr : Assign) : VG visit_assign_expr, visit_binary_expr(expr : Binary) : VG visit_binary_expr, visit_call_expr(expr : Call) : VG visit_call_expr, visit_get_expr(expr : Get) : VG visit_get_expr, visit_grouping_expr(expr : Grouping) : VG visit_grouping_expr, visit_lambda_expr(expr : Lambda) : VG visit_lambda_expr, visit_literal_expr(expr : Literal) : VG visit_literal_expr, visit_logical_expr(expr : Logical) : VG visit_logical_expr, visit_self_expr(expr : Self) : VG visit_self_expr, visit_set_expr(expr : Set) : VG visit_set_expr, visit_super_expr(expr : Super) : VG visit_super_expr, visit_ternary_expr(expr : Ternary) : VG visit_ternary_expr, visit_unary_expr(expr : Unary) : VG visit_unary_expr, visit_variable_expr(expr : Variable) : VG visit_variable_expr

Constructor Detail

def self.new #

Constructor function for the interpreter. Assigns @globals as the current environment. Also defines the standard library functions in the global environment.


[View source]

Instance Method Detail

def execute_block(statements : Array(Stmt), environment : Environment) #

Creates a new environment for a block, and executes the block's statement array.


[View source]
def globals : Kaze::Environment #

The global environment.


[View source]
def globals=(globals : Kaze::Environment) #

The global environment.


[View source]
def interpret(statements : Array(Stmt)) #

Interprets a source file.


[View source]
def interpret(statement : Stmt | Expr | Nil) #

Interprets a line in the REPL. Can execute statements and also evaluate expressions.


[View source]
def resolve(expr : Expr, depth : Int32) #

Resloves an expression.


[View source]
def visit_assign_expr(expr : Expr::Assign) : VG #

Evaluates an assignment expression.


[View source]
def visit_binary_expr(expr : Expr::Binary) : VG #

Evaluates a binary expression.


[View source]
def visit_block_stmt(stmt : Stmt::Block) : Nil #

Executes a statement block.


[View source]
def visit_break_stmt(stmt : Stmt::Break) : Nil #

[View source]
def visit_call_expr(expr : Expr::Call) : VG #

Evaluates a function call.


[View source]
def visit_class_stmt(stmt : Stmt::Class) : Nil #

Interprets a class.


[View source]
def visit_expression_stmt(stmt : Stmt::Expression) : Nil #

Executes an expression statement.


[View source]
def visit_function_stmt(stmt : Stmt::Function) : Nil #

Executes a function statement i.e. a function definition.


[View source]
def visit_get_expr(expr : Expr::Get) : VG #

Evaluates a get expression. Raises an exception if the expression's object is not a class instance.


[View source]
def visit_grouping_expr(expr : Expr::Grouping) : VG #

Evaluates a grouping (parenthesized) expression.


[View source]
def visit_if_stmt(stmt : Stmt::If) : Nil #

Executes an if statement.


[View source]
def visit_lambda_expr(expr : Expr::Lambda) : VG #

Evaluates a anonymous lambda function. This simply creates a new function without a name.


[View source]
def visit_literal_expr(expr : Expr::Literal) : VG #

Evaluates a literal expression.


[View source]
def visit_logical_expr(expr : Expr::Logical) : VG #

Evaluates a logical AND or OR expression.


[View source]
def visit_return_stmt(stmt : Stmt::Return) : Nil #

Executes a return statement.


[View source]
def visit_self_expr(expr : Expr::Self) : VG #

Evaluates self.


[View source]
def visit_set_expr(expr : Expr::Set) : VG #

Evaluates a set expression.


[View source]
def visit_super_expr(expr : Expr::Super) : VG #

Evaluates a super expression.


[View source]
def visit_ternary_expr(expr : Expr::Ternary) : VG #

Evaluates a ternary i.e. conditional expression. The expression on the right only evaluates if the one on the left is false.


[View source]
def visit_unary_expr(expr : Expr::Unary) : VG #

Evaluates a unary expression.


[View source]
def visit_var_stmt(stmt : Stmt::Var) : Nil #

Executes a variable declaration.


[View source]
def visit_variable_expr(expr : Expr::Variable) : VG #

Evaluates a variable expression i.e. a variable being used as an expression.


[View source]
def visit_while_stmt(stmt : Stmt::While) : Nil #

Executes a while statement.


[View source]