Before making a small detour with Valgrind and generic containers, we implemented parsing. A small subset of it anyways. :) In the following couple of posts we are going to start working towards compiling those arithmetic expressions we parsed into bytecode. Before we could compile anything, we need to know what bytecode is, how to create it, and how to store it. In this post we will answer the first of these questions: what is bytecode and why we chose to use it.
We have a working parser that is capable of parsing the four basic arithmetic operators (
/), negation (prefix
-) and grouping (
()). We could continue adding new features to the parser until it fully supports the ASPL language but it would be very boring to go this way. It’s going to be much more interesting to implement the full pipeline, and finally see our virtual machine executing some code, am I right? Today we start working towards a fully operational virtual machine. By the time we finish, we will have our own arithmetic calculator that supports addition, subtraction, multiplication, and division. This may seem like a small step but don’t worry, we will keep adding new features to it until we implement every feature of ASPL.
Working with C is very low level, and always means manual memory management. It is important to have at least one method in place to check for memory leaks. On MacOS, especially if you use XCode, it is quite easy to use Instruments for this. On other platforms, let’s say Linux, Valgrind is one of the best tools.