This project implements a simple interpreter and JIT (Just-In-Time) compiler using Flex, Bison, and C++, capable of executing a subset of a programming language with support for arithmetic expressions, variables, and function calls. It lays the foundation for a JIT compiler using LLVM, and currently works as a tree-walking interpreter over an Abstract Syntax Tree (AST).
- Variable declarations and assignments (
let x = 5;) - Arithmetic operations:
+,-,*,/ - Parenthesized expressions for precedence control
- Built-in function:
print(expr); - AST-based evaluation
- Modular architecture (Lexer, Parser, AST, Evaluator)
- Clean CMake-based build system
jit/
├── include/
│ └── ast.hpp # AST structure: Expression & Statement nodes
├── src/
│ ├── lexer.l # Tokenizer (Flex): breaks input into tokens
│ ├── parser.y # Parser (Bison): builds AST using grammar rules
│ ├── helper.cpp # Interpreter logic (AST evaluation)
│ └── main.cpp # Main function: input loop and glue logic
├── build/ # (Generated) Build files from CMake
├── generated/ # Flex/Bison generated .cpp and .hpp files
└── CMakeLists.txt # CMake configuration for building the project
The compiler is structured into four main stages:
- Uses Flex to convert raw text input into tokens like
LET,IDENTIFIER,NUMBER,PRINT,=,+,;, etc. - Example:
becomes tokens:
let x = 10;LET IDENTIFIER ASSIGN NUMBER SEMICOLON
- Uses Bison to define grammar rules and parse the token stream into an AST.
- For example:
builds a tree representing:
let x = 3 + 5 * 2;= / \ x + / \ 3 * / \ 5 2
- Defines node structures for:
- Binary operations
- Literals
- Variables
- Function calls
- Statement nodes (let, expression, etc.)
- The parser builds these nodes dynamically using
newand pointer types.
- Traverses the AST recursively to evaluate expressions and execute statements.
- Maintains a simple symbol table (map of variables).
- Supports function dispatch (like
print(...)) by name.
> let a = 5;
> let b = 10;
> let c = a + b * 2;
> print(c);
25
| Feature | Example |
|---|---|
| Variable Decl | let x = 42; |
| Arithmetic | x + y * (z - 3) |
| Function Call | print(x); |
- Linux-based system
- CMake (
>=3.10) - Flex (
>=2.6) - Bison (
>=3.0) - GCC or Clang
cd jit/
mkdir -p build
cd build
cmake ..
make
./jitThis will launch a simple REPL-like prompt where you can paste your statements.
- No support for user-defined functions yet
- No type system or error recovery
- Currently uses interpretation, not LLVM codegen (to be added)
- LLVM-based code generation for actual JIT compilation
- User-defined functions and parameters
- Scoped variables and block execution
- Type checking and better diagnostics
- Interactive REPL enhancements
| Name | Role |
|---|---|
| Dhananjay Pundir | Team Lead |
| Aman Singh Rawat | Developer |
| Siddharth Katyal | Developer |
This project is intended for academic and educational purposes and is released under an open-source license.