munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
9.07k stars 1.06k forks source link

[discussion] emitting bytecode from a generated parse tree #801

Open drewbanas opened 4 years ago

drewbanas commented 4 years ago

Just sharing my implementation (in C#) for study purposes:

https://github.com/drewbanas/jcloxcs

It has a modified clox compiler that takes in the list of statements generated by the jlox parser. It takes inspiration from "Writing a Compiler In Go" that built upon the previous interpreter book. Pratt parsing is also used in the parser.

Hoping others might find it helpful!

munificent commented 4 years ago

This is great!

drewbanas commented 4 years ago

Thanks! I learned from great sources. :-)

Splitting the compiler has been a rewarding learning experience and will likely be the basis for my future modifications. The trickiest part was handling the different types of calls. Also somewhat different is catching invalid assignments in the Pratt-modified jlox parser. I wonder how others would have done these.