in Books, Doing Books, Theory of Computation

Theory of Computation #18

The basic loop construct is rather easy to write and looks like this. I used the var A as the counter.

The problem is that doesn’t have a body. All it does it increment its counter until it is zero. So let’s write a function which takes a vector of parsed commands and returns the final state.

Okay, that works. The idea is again pretty basic. You can see that I use a looping function. It does what the name says it does. It loops over a var name. Interesting enough it calls the execute function:

So they basically bootstrap each other. If you followed me alone you noticed that execute is also the interpreter. We write some last tests and we’re done:

It works. This took quite some time, probably the longest so far. But I’m quite proud that I wrote my first interpreter :D

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.