A compiler that works for a smaller subsection of the C language. It compiles a C-like language into MIPS assembly code.
The compiler can take advantage of the following features:
- Integer Literals, Variables
- Variables must be declared before they are used (all declarations before other statements)
- Assignment Statement
- Arithmetic Operators
+, - (binary subtraction), \*, /, %, - (unary minus)
^ (exponentiation) PRE: >= 0
- Boolean Literals, Variables
- Variables must be declared before they are used (all declarations before other statements)
- Assignment Statement
- Relational Operators
<, <=, ==, >=, >, !=
- Boolean Operators
!, &&, ||
- read(comma delimited list of variables)
- Ex.
read(x, y, z)
- Ex.
- print(comma delimited list of expressions);
- Print results on the current line
- Print a space between values
- A newline is not printed
- Ex.
print(2*x, x^3*(z\*w), abc/xyz, c)
- printlines(expression)
- Print expression number of newlines (\n)
- Ex.
printlines(2)
- printspaces(expression)
- Print expression number of spaces
- Ex.
printspaces(3\*n)
- printString(“Literal String”)
- Print a literal representation of the provided string
- if statements including optional else
- while loops
- Uses C syntax & C definition of true (non-zero) and false (zero)
- Size of the array is declared at compile time
- Subscripts can use constants and expressions.
- Ex.
nums[2*i] = z * nums[j-3*k]
- Ex.
$ yacc -d ExprEval.y
OR
$ bison -dy ExprEval.y
$ lex lex.l
OR
$ flex lex.l
$ cc -o comp lex.yy.c y.tab.c SymTab.c Semantics.c CodeGen.c IOMngr.c main.c
$ ./comp <file to compile> <error output file> <compilation output file>
$ spim run <asm file>