Skip to content

Interpreter

The interpreter is the execution engine.

It takes the AST and evaluates it:

Program
│
▼
Statement
│
▼
Expression
│
▼
Runtime Value

For:

let name = "Tanmoy"

the interpreter:

  1. Evaluates "Tanmoy".
  2. Creates a runtime Value.
  3. Stores it in the environment.

Conceptually:

"Tanmoy"
↓
Value::String
↓
Environment
↓
name → "Tanmoy"

For:

print(name)

the interpreter evaluates:

Identifier("name")
↓
Environment.get("name")
↓
Value::String("Tanmoy")

NXL currently has one built-in function:

print("Hello")

The parser creates:

Call
├── callee: print
└── arguments:
└── "Hello"

The interpreter recognizes print as a built-in, evaluates its argument, and sends it to stdout.

For:

print(23)

the output is:

23

The interpreter currently understands:

  • variable declarations
  • literal values
  • variable lookup
  • expression statements
  • blocks
  • print()

The AST and parser already contain more functionality than the interpreter currently executes. This is intentional: the architecture allows language features to be implemented incrementally.