Writing an Interpreter in Object Pascal: Part 2
This is Part 2 of a series I am writing on how to write interpreters in Object Pascal. Part I, published in early 2019, described the construction of a tokenizer and syntax checker for a simple procedural language I named after my dog, Rhodus. Part I ended with a simple calculator application and a full language recognizer.
In Part 2 we will cover the building of the first version of a virtual machine together with a simple assembler. The book then describes combining the virtual machine with the syntax checker for the Rhodus language. In Part 2 we generate the code directly as we parse the source code. In Part 3 of the series, we will separate parsing from code generation via an abstract syntax tree. At the end of Part 2, there will be a very serviceable interpreter that supports user-defined functions, built-in functions, string, and list support together with a range of looping constructs. The big omission from this version is support for libraries, that will come in Part 3.