/pylox

Lox interpreter in Python. Based on Crafting Interpreters by Bob Nystrom

Primary LanguagePythonMIT LicenseMIT

pylox

Pylox is a Lox interpreter, implemented in Python, based on the book Crafting Interpreters by Bob Nystrom.

I am currently working through Chapter 9.

Also, I have implemented some of the chapter challenges so far, but not all. Eventually I want to 100% the Tree-Walk Interpreter section


Table of Contents

Demo

REPL

pylox demo

Verbose REPL

Useful for debugging

pylox demo verbose

Source files

pylox demo src

Installation

Pull from Github

Requires Python 3.10 or later

I use Hatch to manage the Python environment

Challenges

Ch 4. Scanning

  • Support for C-style block comments (NOT nestable)

Ch 5. Representing Code

  • AST print Reverse Polish Notation

Ch 6. Parsing Expressions

  • Comma Operator
  • Ternary Operator
  • Error productions for binary operators without left-hand side expression

Ch 7. Evaluating Expressions

  • [] define "+" so that if one operand is string, it coerces other operand to string I don't really like this behaviour with strings. Between floats and ints this is okay, but Lox anyways only has float type
  • handle zero division error

Ch 8. Statements and State

  • Evaulate expressions in REPL
  • Runtime error when accessing uninitialized variables

Ch 9. Control Flow

Architecture of pylox

cli: handles command line interface (cli) options, cli formatting, stdin/stdout.

utils: helper utilities; not particularly significant to the function of the app, but convenient.

engine: the core of the pylox interpreter

License

pylox is distributed under the terms of the MIT license.