This project implements an interpreter for the HL language. It is built in Java using JavaCC and JJTree to generate and evaluate an Abstract Syntax Tree (AST) with the Visitor pattern.
- HL.jjt
Grammar Definition: Defines the HL language grammar using JJTree. - HLEval.java
Interpreter Logic: Contains the visitor methods to evaluate the AST. - Makefile
Automates the compilation and build process. - runtests
A script for running test cases located in thetests/directory. - tests/
Directory for HL test files.
- Java (JDK 11 or newer)
- JavaCC (v7.0.9 or compatible)
- Build the Interpreter
make
- Run Tests
./runtests
If you prefer compiling manually:
javacc HL.jjt
javac *.java AST/*.java
java HL < your_input_file.hlReplace your_input_file.hl with the actual HL source file.
- Generated from
HL.jjt. - Key nodes include:
ASTvar_decl: Variable declarationsASTfn_decl: Function definitionsASTfn_call: Function callsASTAssign: Variable assignmentsASTPrint/ASTPrintln: Print operationsASTIf,ASTFor,ASTWhile: Control structuresASTsum,ASTmul,ASTdiv,ASTmod: Arithmetic operationsASTcomparison: Comparisons and boolean operatorsASTset,ASTinterval: Set operations
- Each AST node has a corresponding visit method.
- Activation records (
HLActivationRecord) manage variable scopes. - Symbol tables (
HLSymbTab) track variables and their values.
To run an HL program (e.g., example.hl):
java HL < example.hlEnsure your test files are placed in the tests/ directory.
- Add debug print statements in
HLEval.javafor tracing. - Modify
HL.jjtto change the grammar, and update associated AST nodes accordingly.
Enjoy exploring and extending the HL interpreter!