Skip to content

Interpreter ​

The Interpreter serves as the primary entry point for evaluating Abstract Syntax Tree (AST) nodes. It evaluates all the Expression nodes (and some Statement) and returns a PrimitiveValue.

Use ​

ts
const interpreter = new Interpreter(ast, interpreterConfig);

InterpreterConfig ​

OptionTypeDefaultDescription
lazyLoadingbooleanfalseDefer evaluation until the value is demanded. Enables LazyList support.
debugbooleanfalseEmit verbose diagnostic output during AST traversal and evaluation.
outputModeLogicSearchMode"first"Search strategy for logic queries: "first", "all", or "stream".
mutabilitybooleantrueAllow identifiers to be rebound after their initial assignment.

PrimitiveValue ​

The PrimitiveValue is the core data abstraction in Yukigo. It is a comprehensive union type that integrates JavaScript native primitives with custom runtime entities required for multi-paradigma support.

ts
export type PrimitiveValue =
  | number
  | boolean
  | string
  | null
  | void
  | undefined
  | PrimitiveValue[]
  | RuntimeFunction
  | RuntimePredicate
  | LogicResult
  | LazyList
  | RuntimeObject
  | RuntimeClass

In Yukigo, the PrimitiveValue is a first-class citizen. This design ensures that any result produced by the interpreter, whether it is a simple scalar, a functional closure, a logic predicate, or a lazy structure, can be:

  1. Passed as an argument to functions or predicates.
  2. Returned from any evaluable block.
  3. Assigned to identifiers within the EnvBuilder context.

Why does it "evaluate" Statements? ​

The purpose of evaluating Statement nodes is to provide a way to declare things at runtime. For example, we can declare a Variable node with identifier x and body 2 like this:

> x = 2

The Interpreter processes the Variable (a Statement), registers the symbol x in the context, and returns void.

Then, when evaluating the symbol x

> x
2

The Interpreter retrieves the associated PrimitiveValue from the environment.