Inspiration

I was inspired by the idea of understanding how programming languages work under the hood — from tokenizing code to evaluating expressions. While many high-level languages offer flexibility, I wanted to build something lightweight yet powerful from scratch using Java. The goal was to create a minimal interpreter that could evaluate user-written code in real time, support variables, arithmetic, and eventually logic and functions.

What it does

This interpreter allows users to:

Run arithmetic expressions like (3 + 5) * 2

Declare and use variables (let x = 10;)

Evaluate statements in an interactive shell (REPL)

Support basic conditional logic (if, else) (optional depending on your build)

Provide detailed error messages for incorrect inputs

It’s designed to be extendable, so features like loops and functions can be layered in as future improvements.

How we built it

The interpreter is built entirely in Java, following these stages:

Lexical Analysis (Lexer): Breaks the input string into tokens (identifiers, numbers, operators, etc.)

Parser: Uses recursive descent parsing to convert the token stream into an Abstract Syntax Tree (AST)

Interpreter: Walks through the AST to evaluate expressions and statements based on defined semantics

Environment (Symbol Table): Tracks variable definitions and their values

REPL Interface: A simple Read-Eval-Print Loop that allows user interaction line by line

Challenges we ran into

Operator Precedence: Making sure 2 + 3 * 4 correctly evaluates as 14, not 20.

Error Handling: Designing helpful error messages and preventing interpreter crashes from bad inputs.

Scoping: Keeping variable environments consistent during nested expressions and conditionals.

Recursive Parsing: Writing clean, bug-free recursive descent code for various expression types took precision.

Accomplishments that we're proud of

Successfully built a working interpreter from scratch in Java.

Created a modular design that's easy to extend (e.g., adding functions or control flow).

What we learned

Fundamentals of compiler design: lexers, parsers, and interpreters.

Practical use of recursion, tree structures, and symbol tables.

Designing simple but extensible language grammars.

Balancing performance and readability in interpreter design.

What's next for Java Based Interpreter

Add support for functions (with parameters and return values)

Implement while / for loops

Build a web-based or GUI-based REPL using JavaFX or a web framework

Add type checking and runtime error diagnostics

Explore JVM bytecode generation for compiling to .class files

Built With

Share this project:

Updates