Hacker News new | ask | show | jobs
Show HN: Plox – Lox compiler in ~600 LOC from the 'Crafting Interpreters' book (github.com)
2 points by eliasdejong 9 days ago
'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.