The “Helix Interpreter” project is a Python-based interpreter for a custom language, demonstrating fundamental compiler design principles including lexical analysis, parsing, abstract syntax tree (AST) traversal, and semantic evaluation.
The project follows a modular, component-based architecture:
grammar/
: Contains Helix.g4
, the core ANTLR grammar file defining the language’s lexical tokens and syntactic rules. ANTLR generates the Lexer and Parser from this file.builtins/
: Defines the language’s standard library functions (like output <<
) and built-in data types (INTEGER, DOUBLE, STRING, BOOL).core/
: Houses the main interpretation logic.evaluator.py
: Inherits from ANTLR’s HelixVisitor
and implements the Visitor design pattern. It traverses the AST generated by the parser and executes the code.environment.py
& environment_stack.py
: These classes manage variable scopes. An Environment
object represents a single scope (like a function or loop body), and the EnvironmentStack
manages a stack of these objects to handle nested scopes correctly.runtime/
: Orchestrates the execution. interpreter.py
coordinates the parsing and evaluation process, while runner.py
provides the command-line interface.Helix.g4
.Evaluator
traverses the parse tree, executing statements and evaluating expressions recursively.integer
, double
, string
, and bool
with type checking during operations and comparisons to prevent invalid operations.for
or if
.RES_SYM.txt
file listing all identifiers, their final types, values, and scopes.