Skip to main content

pylox

PyPI - Python Version PyPI PyPI - License pre-commit.ci status

Introduction

This is my Python implementation of an interpreter for the Lox programming language from Robert Nystrom's Crafting Interpreters.

Python?

While the text is implemented in Java and C as its high & low-level implementations, I have no idea how to write either of them! Instead, I'll be using Python for the high-level implementation & eventually Rust for the low-level imeplementation.

Differences From Text

For the sake of fitting within a decently sized text, the fully implemented Lox spec omits features that users of other programming languages may miss. Often these are discussed as notes within a chapter, or presented as challenges at the end of a chapter. Significant difference in this implementation from the text reference are noted below.

Defined by Challenges

  • (Chapter 4): Arbitrarily nested block comments (/* ... */)
  • (Chapter 9): break statements are available for for and while loops

User Choice

  • Division by zero returns NaN (Python's float('nan'))
  • Strings may be defined using either " or '
  • Modulo operator (%)
  • Power operator (^)
  • Integer division operator (\)
  • Both floats and integers are represented
    • Return type from operations follows Python3's semantics
  • Containers
    • array()
  • A basic include header system
    • Supports "stdlib" imports (<header_name>) and path imports ("path/to/file")
    • Recursive include not supported
    • Imported source assumed to be valid code

Additional Built-ins:

Unless otherwise noted, behavior mirrors the similarly named Python function.

General

  • input
  • len
  • ord
  • read_text (via pathlib.Path.read_text)
  • str2num
  • string_array
    • Gives a LoxArray whose contents are equivalent to collections.deque(<some string>)

Math

  • abs
  • ceil
  • divmod
  • floor
  • max
  • min

Regex

For methods whose Python equivalent returns Match objects, a LoxArray is returned. The first value in the array will always correspond to match.group(0); if the pattern contains one or more groups then the array will match the output of match.groups()

  • re_findall
  • re_match
  • re_search
  • re_sub

Stats

  • mean
  • median
  • mode
  • std

Pure lox headers

  • <array_sum>
  • <hello_world>
  • <map>
  • <split_on>

Release files for sco1-pylox 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sco1-pylox 0.5.2
File Size Uploaded
sco1_pylox-0.5.2.tar.gz 27.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sco1-pylox 0.5.2
File Interpreter ABI Platform
sco1_pylox-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 62.8 kB

Release files / sco1_pylox-0.5.2.tar.gz

Download URL sco1_pylox-0.5.2.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c67d5874dfa3fdb40980d3662a6032d4a126b3076ef38c70da1753f3f4ed2c21
BLAKE2b-256 checksum
How to use checksums
356483f366d57aa1037a9071a85b206955b62524d3353f5d923866fa0587935f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.

Transparency log

Release files / sco1_pylox-0.5.2-py3-none-any.whl

Download URL sco1_pylox-0.5.2-py3-none-any.whl
Size 35.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17ce6ab11b860407e84d8045875623d93f7fa7e5586348fd20905aee560f5d9b
BLAKE2b-256 checksum
How to use checksums
b77f0401c8b5a03e1d16135467ca4be8c8682ee0b106d8cc652f35149c4af35a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page