Skip to content

Md-Talim/codecrafters-interpreter-java

Repository files navigation

progress-banner

Lox Interpreter

This project is a Java implementation of the Lox interpreter, built as part of the Codecrafters "Build your own Interpreter" challenge. The challenge follows the book Crafting Interpreters by Robert Nystrom.

Overview

Lox is a simple scripting language. This interpreter project covers various aspects of language implementation, including tokenization, parsing, and interpreting the abstract syntax tree (AST).

Features

  • TokenizationScanner converts source code into tokens (keywords, identifiers, literals, operators).
  • ParsingParser converts tokens into an AST, handling expressions and statements.
  • ASTExpr and Stmt define the structure of Lox code.
  • InterpretationInterpreter walks the AST to execute code (variables, functions, control flow).
  • Error Handling – Handles syntax and runtime errors.
  • Environment & ScopeEnvironment manages nested scopes for variables and functions.
  • Function CallsFunction supports parameter passing and return values.
  • Native Functions – Includes clock to return the current time.

Usage

Running the Interpreter Locally

To run the interpreter locally, use the your_program.sh script:

your_program.sh run <filename>

Commands

Command Description
tokenize <filename> Tokenizes the source code and prints the tokens.
parse <filename> Parses the source code and prints the AST.
evaluate <filename> Evaluates a single expression and prints the result.
run <filename> Runs the entire Lox program.

Example

To run a Lox program:

your_program.sh run test.lox

Acknowledgments

About

My solution to the CodeCrafters interpreter challenge (Lox language).

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •