Now that we have a new machine language, we can write some programs using it and try to build an interpreter for these programs. In addition, it is possible to use the nom library, already seen in Chapter 8, Using a Parser Combinator for Interpreting and Compiling, to ease the building of this sort of interpreter.
However, before we start coding, let's consider the possible techniques to execute a machine language program. In fact, there are at least three possible ways to execute a machine language program without having real hardware:
- Technique 1: Interpreting it just as the hardware would interpret it. This is the technique used in the previous sections to interpret the sieve of Eratosthenes program in the word_machine_sieve project.
- Technique 2: First, parsing it all and transforming it into a high-level data structure, then interpreting this data structure.
- Technique 3: Translating it into another programming language, and then using an interpreter...