evaluator

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package evaluator implements the evaluation logic for the Monke programming language.

The evaluator takes an Abstract Syntax Tree (AST) produced by the parser and evaluates it to produce values. It implements a tree-walking interpreter that recursively traverses the AST and executes the corresponding operations.

Key features:

  • Evaluation of all language constructs (expressions, statements, literals, etc.)
  • Support for variables and environments
  • Function calls and closures
  • Error handling and reporting
  • Built-in functions
  • Optimized for performance with minimal memory allocations
  • Object caching for common values (integers, strings, booleans)
  • Pre-allocation of collections to reduce reallocations

The main entry point is the Eval function, which takes an AST node and an environment and returns an object representing the result of the evaluation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TRUE represents the boolean value 'true' within the Monke language and is used in logical evaluations and comparisons.
	TRUE = &object.Boolean{Value: true}

	// FALSE represents the boolean value 'false' within the Monke language.
	FALSE = &object.Boolean{Value: false}

	// NULL represents the singleton null value in the Monke language,
	// used to denote the absence of a value or a null result.
	NULL = &object.Null{}
)

Functions

func Eval

func Eval(node ast.Node, env *object.Environment) object.Object

Eval evaluates the given AST node in the given environment and returns the result. This is the main entry point for the evaluator and handles all types of AST nodes. It recursively evaluates expressions and statements, maintaining the environment for variable lookups and assignments.

For expressions, it returns the resulting value. For statements, it either returns a value (for expression and return statements) or nil (for let statements). If an error occurs during evaluation, it returns an Error object.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL