A Python interpreter for the Lox programming language.
Project description
pylox
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):
breakstatements are available forforandwhileloops
User Choice
- Division by zero returns
NaN(Python'sfloat('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
includeheader system- Supports "stdlib" imports (
<header_name>) and path imports ("path/to/file") - Recursive
includenot supported - Imported source assumed to be valid code
- Supports "stdlib" imports (
Additional Built-ins:
Unless otherwise noted, behavior mirrors the similarly named Python function.
General
inputlenordread_text(viapathlib.Path.read_text)str2numstring_array- Gives a
LoxArraywhose contents are equivalent tocollections.deque(<some string>)
- Gives a
Math
absceildivmodfloormaxmin
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_findallre_matchre_searchre_sub
Stats
meanmedianmodestd
Pure lox headers
<array_sum><hello_world><map><split_on>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sco1_pylox-0.5.2.tar.gz.
File metadata
- Download URL: sco1_pylox-0.5.2.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c67d5874dfa3fdb40980d3662a6032d4a126b3076ef38c70da1753f3f4ed2c21
|
|
| MD5 |
839e002c6b9ece10203204a679c8c5b1
|
|
| BLAKE2b-256 |
356483f366d57aa1037a9071a85b206955b62524d3353f5d923866fa0587935f
|
Provenance
The following attestation bundles were made for sco1_pylox-0.5.2.tar.gz:
Publisher:
pypi_release.yml on sco1/pylox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sco1_pylox-0.5.2.tar.gz -
Subject digest:
c67d5874dfa3fdb40980d3662a6032d4a126b3076ef38c70da1753f3f4ed2c21 - Sigstore transparency entry: 630344802
- Sigstore integration time:
-
Permalink:
sco1/pylox@84da95eaa7f0ef8bfd1a18f980427979c1c1a2b6 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/sco1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@84da95eaa7f0ef8bfd1a18f980427979c1c1a2b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sco1_pylox-0.5.2-py3-none-any.whl.
File metadata
- Download URL: sco1_pylox-0.5.2-py3-none-any.whl
- Upload date:
- Size: 35.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17ce6ab11b860407e84d8045875623d93f7fa7e5586348fd20905aee560f5d9b
|
|
| MD5 |
5b873993ae38908465c2cdca01f3bc2c
|
|
| BLAKE2b-256 |
b77f0401c8b5a03e1d16135467ca4be8c8682ee0b106d8cc652f35149c4af35a
|
Provenance
The following attestation bundles were made for sco1_pylox-0.5.2-py3-none-any.whl:
Publisher:
pypi_release.yml on sco1/pylox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sco1_pylox-0.5.2-py3-none-any.whl -
Subject digest:
17ce6ab11b860407e84d8045875623d93f7fa7e5586348fd20905aee560f5d9b - Sigstore transparency entry: 630344805
- Sigstore integration time:
-
Permalink:
sco1/pylox@84da95eaa7f0ef8bfd1a18f980427979c1c1a2b6 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/sco1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@84da95eaa7f0ef8bfd1a18f980427979c1c1a2b6 -
Trigger Event:
release
-
Statement type: