Skip to main content

A Python interpreter for the Lox programming language.

Project description

pylox

PyPI - Python Version PyPI - Version PyPI - License pre-commit.ci status Code style: black Open in Visual Studio Code

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()

Additional Built-ins:

Unless otherwise noted, behavior mirrors the similarly named Python function

  • abs
  • ceil
  • divmod
  • floor
  • input
  • len
  • max
  • mean
  • median
  • min
  • mode
  • ord
  • read_text (via pathlib.Path.read_text)
  • std
  • str2num
  • string_array
    • Gives a LoxArray whose contents are equivalent to collections.deque(<some string>)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sco1-pylox-0.3.2.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

sco1_pylox-0.3.2-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file sco1-pylox-0.3.2.tar.gz.

File metadata

  • Download URL: sco1-pylox-0.3.2.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for sco1-pylox-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b99aec38756f621548fa18402300dd7336f33dc00ff8ce345cbe46733e76b4ae
MD5 201caf8bfc14db14717c2175b8f6837f
BLAKE2b-256 e85a398cfad5ec5fe4e10441e377767b0808178ec0d9d2260d74700868f66429

See more details on using hashes here.

Provenance

File details

Details for the file sco1_pylox-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: sco1_pylox-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for sco1_pylox-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24b560bf5fed9b19523da30b6ada3ab3806deacc6d930126ce6e288f41c307ab
MD5 95f0da67dff49ac8cc94734cb2271651
BLAKE2b-256 53a1ee4ba2f4b42dd0c1aa33b421e79b61e400236f335cedd416efbc7a14f4ac

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page