About a month ago I stumbled on a series of blog post called Let’s build a simple interpreter by Ruslan Spivak. In these blog posts the author write about building a simple interpreter for the
Pascal programming language in
Python. It is very well written and explained, I would even say that all the concepts are explained better than in the compiler course I took at the university.
In that class I had to write a
Pascal compiler not interpreter in
C++ and with tools like
yacc so I remembered most concepts but the interpreter is a bit different than a compiler and not using any external tools makes you think more about the problem.
I felt a bit nostalgic and wanted to tackle an algorithmically challenging problem, especially because
Pascal was my first programming language back in high school so I decided to follow along and write a simple
Pascal interpreter in
Swift, the language I switched to from C# nearly a year ago.
Swift is a different language than
Python so I had to do many things differently, especially those where the Python implementation relayed on the dynamicity of the language.
But the biggest challenge was that the series ended before introducing function calling and the call stack so I had to come with a good way to do this. I also wanted to support recursion and basic loops and flow controls.