Skip to content

MartinLwx/pylox

Repository files navigation

What's Lox

Lox is a dynamically typed, interpreted script language, which is designed by Robert Nystrom for his book Crafting interpreters.

What's pylox

An interpreter for the Lox programming language implemented in Python, following a tree-walk approach. The original book utilizes Java to build the interpreter, referred to as jlox. To maintain consistency, I chose the name pylox for the Python implementation. 💅

Structure

.
├── LICENSE
├── tests
├── README.md
├── environment.py                # for scopes
├── expr.py                       # all AST nodes
├── tokens.py                     # all Lox tokens
├── scanner.py                    # chars  ---> tokens
├── parser.py                     # tokens ---> AST
├── resolver.py                   # do semantic analysis by traversing AST
├── interpreter.py                # tree-walk interpreter
├── run_tests.py                  # run all tests
├── pylox.py                      # main
├── errors.py                     # some error handling
├── ast_printer.py                # print an AST in LISP style
└── utils.py                      # set arity for built-in function. i.e. clock

Dependency

Python 3.10+

Usage

# execute a lox file
$ python pylox.py foo.lox

# REPL
$ python pylox.py

Testing

The tests are copied from crafting interpreters

Note that I disable the benchmark tests because pylox is quite inefficient.

$ python run_tests.py
# --------- Summary ----------
#   [PASS]: 231 / 245 -- 94.29%
#   [SKIP]:  14 / 245 -- 5.71%
#   [FAIL]:   0 / 245 -- 0.00%
# ----------------------------

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages