Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A compiler and simulator class project at RIT

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 smada
Octocat-spinner-32 smadatron
Octocat-spinner-32 tests
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README
README
While at RIT my Computer Science 4 project was a simulation of a simple operating system with that compiler.  A compiler and simulator were created. The code that the compiler could interpret was similar to basic. The simulator would run the assembly that the compiler generated.

Here is an example of some of the code that the compiler had to understand:

0 let x = 10
10 let x = x * 10
20 let x = 10 * x
30 print x
99 end

I normally wouldn't put up school assignment, but I was proud of the compile that I created.  We only had four weeks to complete the entire project (which consisted of many smaller components including the compiler). This gave us maybe a week to actually code the compiler. Out of the forty or so groups only two finished (include mine of course). The biggest problem for most groups beyond simply coding the compiler was trying to debug the compiler to make sure it was generating correct output.

Each generated assembly statement such as <code>2098</code> contained two pieces of information. The action (in this case 20 = LOAD) and what to perform it on (in this case slot 98 in memory). Attempting to decider the generated assembly in our heads quickly became annoying and time consuming. I modified my compiler to generate smart comments to go with the assembly so that the output could quickly and easily be read and debugged. There were a number of other features in the compiler above and beyond the original project requirements, but it was this feature which made me keep the code and post it here.


Here is a sample output of the above code generated by the compiler with smart debug turned on:

Staring ASM output.

     ; Smada Instruction: let x = 10
     ;     Expression Starting.
2098 ; 0: Load Num: 10
     ;     Expression Ending.
2199 ; 1: let x = Expression (now in the register).

     ; Smada Instruction: let x = x * 10
     ;     Expression Starting.
2099 ; 2: Load variable: x
3398 ; 3: Register * 10
     ;     Expression Ending.
2199 ; 4: let x = Expression (now in the register).

     ; Smada Instruction: let x = 10 * x
     ;     Expression Starting.
2098 ; 5: Load Num: 10
3399 ; 6: Register * x
     ;     Expression Ending.
2199 ; 7: let x = Expression (now in the register).

     ; Smada Instruction: print x
     ;     Expression Starting.
2099 ; 8: Load variable: x
     ;     Expression Ending.
2197 ; 9: Store the register in temporary.
1197 ; 10: Print out the above expression (saved in temporary).

     ; Smada Instruction: end
4300 ; 11: End
.
..
...
..
.
     ; Variables Start.
0    ; Location: 97, Temporary Variable
10   ; Location: 98, Fixed Value.
0    ; Location: 99, Variable: x
     ; Variables End.


There are two components that are included with the source.  smada is a compiler and smadatron can execute binaries created by smada.  Use qmake to create the makefiles.
Something went wrong with that request. Please try again.