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):
break
statements are available forfor
andwhile
loops
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
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
- Supports "stdlib" imports (
Additional Built-ins:
Unless otherwise noted, behavior mirrors the similarly named Python function.
General
input
len
ord
read_text
(viapathlib.Path.read_text
)str2num
string_array
- Gives a
LoxArray
whose contents are equivalent tocollections.deque(<some string>)
- Gives a
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>
<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
Built Distribution
File details
Details for the file sco1-pylox-0.5.0.tar.gz
.
File metadata
- Download URL: sco1-pylox-0.5.0.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78dffd3df194b298b9fbf05199e81df4de3fc60f524a3e344993a4f81f4908da |
|
MD5 | 70448e9771cd4fab61ea36cfcafe94cd |
|
BLAKE2b-256 | 93a10506955e555fcedf2663edd5bff7c7020553171b9d24405231116c768a4f |
Provenance
File details
Details for the file sco1_pylox-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: sco1_pylox-0.5.0-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 847b5279305a5e578f111aaa23284085587752e0cfde67c57e6648970de99c50 |
|
MD5 | e98bda00fb877b00cece7da3468e9490 |
|
BLAKE2b-256 | 2f50fbaa281956a091741d920a0b72d53af47cb57761640c76f2a933752bd5f3 |