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

Sorry for the off-topic but can someone guide me about the roadmap/resource how one can make a toy/hobby language(even an intepretator language)? I might like to give it a try either in Python or Go and it could be a good excuse to refresh my compiler/language course I took 23 years back



There is a pair of books called "writing an interpreter in Go" and "writing a compiler in Go" If I remember their names, pretty accessible.

There is also the outstanding "Crafting Interpreters" by Robert Nystrom, this book and its author hold a very special place in my heart. Before I read this book I was stuck at the "+-*/ calculator" level in compilers and interpreters, intimidated by the depth and breadth of further material. This book teaches you how to make a full blown scripting language with first class closures and classes, first as an interpreter running on java (high level enough to get the intimidated beginner started and focused on the task, yet still a challenging learning experience) then as a {bytecode compiler, VM} pair in C be because this is how all the cool kids write their interpreters and compilers. Accessible if there was ever such a thing in the world, I mean it : if you understand how linked lists, hash maps and trees work, you're good to go. The icing on the cake is that the whole thing is free on a website by the same name the author made, the same thing he did with his other book about Game Programming Design Patterns, it's an astonishing act of charity, I really wish to meet this guy. An awesome personality and a great teacher. You will remember his voice and manner of speech for a lot of time.

There is also the book "elements of computing systems" aka "From Nand To Tetris", where the authors walk you through creating a full computing stack from the NAND logic gate to the OS. Starting from chapter 6 through 11, you write an assembler for the hardware, then implement a VM running on the assembler, then implement a java-like language on top of the VM.

These things are just off the top of my head, there is a massive trove of material in YouTube and the rest of the Internet.


I learned best in Scheme because you don't need to parse your input and can just evaluate a tree[0] (Parsing is, in my opinion, the most boring part about writing an interpreter!)

Chapter 7 of Crafting Interpreters lays out how an evaluator works in a pretty clean way [1]. I've also blogged about evaluating ASTs in JavaScript [2]

Lastly, Gary Bernhardt took it a step further and instead of "evaluating" code, "compiled" it to JavaScript (this tutorial uses Ruby) [3]. Very much a mind-blown moment for me.

Have fun!! Writing interpreters remains one of my favorite things to do when learning a new programming language.

[0] https://www.youtube.com/watch?v=aAlR3cezPJg

[1] https://craftinginterpreters.com/evaluating-expressions.html

[2] https://thatjdanisso.cool/programming-languages

[3] https://www.destroyallsoftware.com/screencasts/catalog/a-com...


Implementing a Webassembly interpreter in python for fun: https://youtu.be/r-A78RgMhZU


Another link, that I picked up from some other HN thread: Resources for Amateur Compiler Writers https://c9x.me/compile/bib/


"The elements of computing systems" aka "Nand to Tetris" takes you through the process and I could understand it despite not having a degree. Highly recommended.




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

Search: