XJTU-SE Grade 3 Compiler Practice.
-- A fake compiler, implementing a simple language.
'Code to Quads' transformation. No assembly code generation. However, it won't be too much work to transfer the quads to assembly code.
Language features are as follows:
Supports basic types including integers(int), real numbers(float), characters(char), booleans(bool)
+, ++, -, --, *
<, <=, =, !=, >, >=
&, |, ! (Nobody is willing to type ∨, ∧, and ⌐, Okay?)
Provides support for multi-dimensional arrays, like "a[1, 2] := 3".
Provides support for "if-then", "it-then-else" structure and "switch-case" structure
"while-do" and "do-while" structures will be implemented.
It's not an OOP language, but the basic procedure-calling mechanism is necessary.
As long as some procedures are called, they are defined. Certainly, variables should also be defined.
With a text file as the input, a sequence of quadruples (which can be easily transferred to assembly language) will be generated. Invalid code in the text file will cause the compiler to report error type and error position. Also, an output file will be generated along with the analyzation result on the screen.
function func(int x, int y) {
x = x + y
};
int a, b;
a := 2;
while (a<20 & b>8) do {
if a>10 || b<16 then {
if a<15 then {
a := 19;
b := 15
call func(a, b);
} else {
a := 11;
b := 9
};
} else {
a := 1;
b := 17
};
};