• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lox interpreter written in Lox

LoxLox

LoxLox is an interpreter for Crafting Interpreters' Lox language written in ... Lox.

Below are a few notes about running LoxLox, but you can read more about LoxLox here.

How to run LoxLox

First clone the LoxLox repo as well as the Crafting Interpreters one:

$ git clone https://github.com/benhoyt/loxlox
$ git clone https://github.com/munificent/craftinginterpreters

JLox

Then patch the Crafting Interpreters repo to add the required builtins to JLox (getc, chr, etc) and build JLox:

$ cd craftinginterpreters
$ git apply ../loxlox/jlox_diff.patch
$ make jlox
$ cd ../loxlox

Now you're ready to run LoxLox (input is passed to LoxLox on stdin):

$ 
$ ./jlox lox.lox < example.lox
1
4
9
16
Waddles quacks
6
105
$ ./jlox lox.lox < sum.lox 
4.99995E9
$ echo 'print "Hello world!";' | ./jlox lox.lox 
Hello world!

CLox

Thanks to gloria-mundi's patch, you can now even run LoxLox under CLox. Patch the Crafting Interpreters repo in much the same way as above:

$ cd ../craftinginterpreters
$ git apply ../loxlox/clox_diff.patch
$ make clox
$ cd ../loxlox

You should now be able to run the examples the same way as above, but replace ./jlox with ./clox. It's about 6x as fast -- see the benchmarks!

Running the tests

To run the Lox test suite under LoxLox, use this command:

$ python3 test.py

Note that several tests will fail. That's expected -- the code works; the remaining failures are only from differences in the runtime error messages between JLox and LoxLox.

To run the tests and diff against the git-committed failures file (should be no diffs):

$ python3 test.py > failures
$ git diff failures

Contact me

Contact me if you have any feedback or suggestions. And if you get LoxLox to run under LoxLox ... mind blown.

More Repositories

1

inih

Simple .INI file parser in C, good for embedded systems
C
2,402
star
2

goawk

A POSIX-compliant AWK interpreter written in Go, with CSV support
Go
1,920
star
3

scandir

Better directory iterator and faster os.walk(), now in the Python 3.5 stdlib
Python
529
star
4

pygit

Just enough git (written in Python) to create a repo and push to GitHub
Python
314
star
5

countwords

Playing with counting word frequencies (and performance) in various languages.
Rust
306
star
6

protothreads-cpp

Protothread.h, a C++ port of Adam Dunkels' protothreads library
C++
178
star
7

pybktree

Python BK-tree data structure to allow fast querying of "close" matches
Python
169
star
8

ht

Simple hash table implemented in C
C
148
star
9

pyast64

Compile a subset of the Python AST to x64-64 assembler
Python
136
star
10

go-routing

Different approaches to HTTP routing in Go
Go
120
star
11

mugo

Mugo, a toy compiler for a subset of Go that can compile itself
HTML
108
star
12

littlelang

A little language interpreter written in Go
Go
92
star
13

third

Third, a small Forth compiler for 8086 DOS
Forth
75
star
14

go-1brc

My Go solutions to the One Billion Row Challenge
Go
74
star
15

prig

Prig is for Processing Records In Go. Like AWK, but snobbish.
Go
64
star
16

gogit

Just enough of a git client (in Go) to init a repo, commit, and push to GitHub
Go
51
star
17

cdnupload

Upload your site's static files to a directory or CDN, using content-based hashing
Python
50
star
18

web-service-stdlib

Rewrite of Go RESTful API tutorial using only the stdlib
Go
49
star
19

simplelists

Tiny to-do list web app written in Go
Go
48
star
20

pas2go

Pascal to Go converter (converts a subset of Turbo Pascal 5.5)
Pascal
42
star
21

symplate

Symplate, a simple and fast Python template language (NOTE: no longer maintained; use Jinja2 or Mako instead)
Python
30
star
22

nibbleforth

A very compact stack machine (Forth) bytecode
Python
29
star
23

zztgo

Port of ZZT to Go (using a Pascal-to-Go converter)
Go
26
star
24

gosnip

Run small snippets of Go code from the command line
Go
24
star
25

python-pentomino

Pentomino puzzle solver using Python code generation
Python
20
star
26

benhoyt.github.com

Source code for my website
HTML
18
star
27

betterwalk

BetterWalk, a better and faster os.walk() for Python -- DEPRECATED, see my "scandir" project
Python
17
star
28

fe

Bruce Hoyt's Forth Editor (Dad's editor that I grew up coding with)
Forth
16
star
29

namedmutex

namedmutex.py, a simple ctypes wrapper for Win32 named mutexes
Python
15
star
30

soft404

Soft 404 (dead page) detector in Python
Python
13
star
31

io-performance

Code repo for https://benhoyt.com/writings/io-is-no-longer-the-bottleneck/
Go
13
star
32

awkmake

Code to go with my article "The AWK book's 60-line version of Make"
Awk
13
star
33

repike

Rob Pike's simple regex matcher converted to Go
Go
11
star
34

benos

A tiny 32-bit Forth operating system I wrote when I was 16
Forth
8
star
35

counter

Fast hash table for counting short strings in Go
Go
7
star
36

false-forth

A False compiler and interpreter written in ANS Forth
Forth
7
star
37

py-1brc

Optimising the One Billion Row Challenge (1BRC) in Python
Python
5
star
38

mro

MRO is not an ORM - Map Rows to Objects with web.py
Python
2
star
39

snappass-test

Demo of Juju K8s sidecar charm with Pebble
Python
2
star
40

circle

Draw circles using the Bresenham Circle Algorithm in Go
Go
2
star
41

interpspeed

Test interpreter speed of various language VMs
Python
1
star
42

boggle

Boggle solver competition
Python
1
star