A basic compiler for a simulated machine using a language called Simple
This was part of an exercise in the textbook for an intro class. To anyone reading this it's unlikely that you'll find anything of interest in here. Also note that it's currently unpolished, I'm still working on expanding it's features.
- Clone this repo.
- In your terminal / command prompt cd into the directory
- Run "./a.out addProg.simple.txt output.txt"
In this example addProg.simple.txt is a program to add to ints together, so in your terminal / command prompt you see tons of printf statements being output (sorry about that), then it'll ask you for a number - enter something, and do the same for the next prompt. Then it prints the execution steps
loading
adding
storing
loading
storing
Then it'll spit out the answer
3
After that it prints out the registers and the memory.
The syntax for the run command is thus:
$ [your executable] [the program written in simple you wish to run] [a file that simpletron will write the 'machine code' into] [an option flag]
ex1.simple.txt - ex5.simple.txt
ex7.simple.txt
addProg.simple.txt
modtest.simple.txt
modulus.simple.txt
The language syntax rules are documented in syntax.txt
For anyone learning computer science much of the material for the compiler exercise is freely available on the author's website if you want to build a 'compiler' yourself.
http://www.deitel.com/bookresources/chtp8/CompilerExercises.pdf