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

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.5.1.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

sco1_pylox-0.5.1-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sco1-pylox-0.5.1.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for sco1-pylox-0.5.1.tar.gz
Algorithm Hash digest
SHA256 58dc53346cda3c8858b0b22aeafce6a7bfe063781a45b3075c18ec065597a00b
MD5 baa72f7e9f51fddead693630dfa6b2a9
BLAKE2b-256 bb5cafd40e3f179d659737549ba4420db974c12ed43d3bd5c4cfaef6a0de0dba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sco1_pylox-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for sco1_pylox-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2acdb8e3c794bc666927de939cb263ef245240e1bc1bfc1736665ccaa594fe
MD5 926ca317f46a6d37c15a08c80f7e2c4f
BLAKE2b-256 80411d130a5f6b4727b3680b293fa928ca462ae72769fd9619eb3abcfa4ceffe

See more details on using hashes here.

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