Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Let’s Build a Simple Interpreter, Part 18: Executing Procedure Calls (ruslanspivak.com)
84 points by ingve on Feb 23, 2020 | hide | past | favorite | 5 comments


I spent several years reading books on interpreters and compilers back in the days, but it wasn't until I discovered Forth that I managed to get a language of my own up and running.

While simpler than the books I had to force myself through, there is still plenty of stuff in here that's not relevant for a first language, nor fundamental to programming languages overall.

Once you have a feedback loop to play around with, you have a better idea where you're aiming and can go look for the theory you actually need to get there.

https://github.com/codr7/gfoo


One way to get your feet wet is to write an eval function for a small language like "basic arithmetic language" in your programming language of choice. Allow only an int type, a few operators ( add, sub, mul ), etc. Then have eval parse then run a statement(s) from "basic arithmetic" and you'll get an idea of how interpreters work. From there you can delve into theory and writing interpreters for more complex languages. I believe in doing first and then learning theory after. Also, you can try writing eval in an OO language, functional language and procedural language to get a deeper grasp of the differences between these programming paradigms.


Indeed, that's pretty much where I started out; Arithmetic evaluators and template engines.

But it's a giant leap from there to Pascal, which is why I like to recommend Forth as a stepping stone.


It took me a while to finally publish this part. :) If you've waited for a long time for this to happen, thanks for your patience.


For a topically related effort see the oft featured and outstanding book at http://craftinginterpreters.com. (I'm not affiliated.)




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

Search: