Simple compiler
The compiler I present convert a Pascal style language into a 0 address assembler type (based only on a stack). Here how the source language looks like:
// // example // FUNCTION truc (a, b) VAR c; BEGIN truc := a + b; END FUNCTION toto (a, d) VAR b, c; BEGIN b := 2 * (a + 3) * 4 + 56 + truc (5 + d, 4 * a + 5); toto := b + d; END
The target language code for this example is as follows:
truc: 0 0 4 PICK 4 PICK ADD 3 ROLL DROP 2 ROLLD 2 ROLL 4 ROLLD 3 DROPN RTN toto: 0 0 0 2.000000 6 PICK 3.000000 ADD MULT 4.000000 MULT 56.000000 ADD 5.000000 6 PICK ADD 4.000000 8 PICK MULT 5.000000 ADD truc ADD 3 ROLL DROP 2 ROLLD 2 PICK 5 PICK ADD 4 ROLL DROP 3 ROLLD 3 ROLL 5 ROLLD 4 DROPN RTN
[edit]
Design
Here are the implementations of this compiler:


