Interpreter
Interpreter
Section titled “Interpreter”The interpreter is the execution engine.
It takes the AST and evaluates it:
Program │ ▼Statement │ ▼Expression │ ▼Runtime ValueVariable declaration
Section titled “Variable declaration”For:
let name = "Tanmoy"the interpreter:
- Evaluates
"Tanmoy". - Creates a runtime
Value. - Stores it in the environment.
Conceptually:
"Tanmoy" ↓Value::String ↓Environment ↓name → "Tanmoy"Variable lookup
Section titled “Variable lookup”For:
print(name)the interpreter evaluates:
Identifier("name") ↓Environment.get("name") ↓Value::String("Tanmoy")Built-in print()
Section titled “Built-in print()”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:
23Current runtime
Section titled “Current runtime”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.