Show HN: Plox – Lox compiler in ~600 LOC from the 'Crafting Interpreters' book

Python port of the Lox language from the 'Crafting Interpreters' book (www.craftinginterpreters.com/) - eliasdejong/plox
2 points by eliasdejong 91 days ago github.com 0 comments
Summary not yet generated for this article.

Original Text

'Crafting Interpreters' is Bob Nystrom's book that teaches you how to build a compiler from scratch. It is an excellent resource and I can highly recommend it. Really light to read and walks you through all the concepts step-by-step.

The first part of the book builds a compiler for the 'Lox' toy language in Java. While I have nothing against Java, personally I have never used it much so I decided to go through the first part of the book writing the code snippets in Python, a language I'm more familiar with.

My implementation is probably not remarkable against the list of other implementations (https://github.com/munificent/craftinginterpreters/wiki/Lox-...), though I tried to minimize the amount of 'object oriented' language features in Python that I use. The AST is also stored 'flat' as a list. Personally I find this style of code much easier to read and understand.

LOC breakdown: scanner ~130, parser ~350, interpreter ~90, type definitions ~200

I'm publishing the repo under MIT so that perhaps it might be useful to others also learning about compilers.

Comments (0 of ) ⌛

Loading more comments... ⌛
Scroll down to load more comments
No comments available.
Type to search HN and engineering blog articles
Press Escape to close  |  ↑↓ to navigate  |  Enter to open