Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

building a compiler can be as easy as building an interpreter

I prefer this demonstration to the one in that paper:

Interpreter: https://news.ycombinator.com/item?id=8558822

JIT compiler: https://news.ycombinator.com/item?id=8746054

To make things more interesting, it's "real syntax", i.e. C-like, rather than the "almost no parsing required" syntax of a Lisp, even smaller than TCC, and yet it can still compile itself.

C4 and the few variants it's spawned have probably become my favourite family of tiny, understandable, but complete compilers. The sheer elegance and simplicity --- one file of less than 1K lines --- makes studying them highly recommended. Almost all the other tiny/teaching/toy compilers I've seen are larger, less capable, or both. I don't know if anyone has made a variant of C4 that generates an AST, but doing that would probably not be too difficult either, and then you'd have a tiny compiler you could experiment on with optimisation and such.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: