About

The project

This project began as an attempt to go beyond just using programming languages and actually understand how they work under the hood. Instead of treating a language as a black box, the goal was to build one from scratch—starting from raw source code and turning it into something executable. The interpreter is inspired by the ideas in the book "Crafting Interpreters", but the implementation is adapted, refined, and extended as part of a personal learning journey. The focus was not only to make a working language, but to deeply understand each stage involved in language design.

Building this interpreter provided hands-on experience with core concepts of programming languages. It helped in understanding how lexical analysis breaks code into tokens, how parsing constructs a structured representation of the program, and how evaluation executes that structure step by step. Beyond the technical pipeline, the project also highlighted important design decisions—such as how scoping works, how functions and classes behave as first-class values, and how object-oriented features like inheritance and dynamic fields can be implemented in a simple yet flexible way.

Implementation

The interpreter is written in Java and follows a classic architecture: scanner → parser → resolver → evaluator. The scanner converts source code into tokens, the parser builds an abstract syntax tree (AST), the resolver performs static analysis for scope and variable binding, and the evaluator walks the AST to execute the program.

A handwritten recursive-descent parser is used to keep the implementation simple and readable while still being powerful enough to handle the full grammar of the language. Variable scope is managed using an environment chain, allowing nested blocks and closures to work naturally. The language supports first-class functions and classes, dynamic field assignment, and single inheritance with method resolution through the superclass chain. Features like this and super are implemented to enable object-oriented behavior without introducing unnecessary complexity.

Influences

Heavily influenced by Crafting Interpreters by Robert Nystrom, though the implementation diverges significantly in…

Author

Built by Sunny. Feel free to reach out or open issues on GitHub.