3 ms·
Let’s Build a Simple Interpreter, Part 18: Executing Procedure Calls
- codr7 7y agoI 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 https://github.com/codr7/gfoo
- dntbnmpls 7y agoOne 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.
- codr7 7y agoIndeed, 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.
- smueller1234 7y agoFor a topically related effort see the oft featured and outstanding book at http://craftinginterpreters.com http://craftinginterpreters.com. (I'm not affiliated.)
- rspivak 7y agoIt 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.