next up previous
Next: Possible extensions (optional) Up: Writing a MOOL compiler Previous: Static check of a MOOL

Translating a MOOL program

The last step in writing a MOOL compiler is the translation to a C program. Observe that the translation of at least the following MOOL constructs is trivial, since they are very similar in C: The only non trivial translations will be those of the following MOOL constructs.
ClassDeclaration
which will be replaced by a struct and one function per NewDeclaration or MethodDeclaration.
NewDeclaration
which will have a returned type in C (i.e. the suitable struct)
MethodDeclaration
which will have the return type int.
Assignment
for which we need to say how we manage objects. A possible and reasonable solution is to use a pointer to a struct.
We give some precisions for the translation of assignments. Let us consider a checked assignment
LeftValue := RightValue
In the translated C code the LeftValue will be In the latter case, the assignment means simply that the object referred by RightValue is pointed to by the id of LeftValue. Hence this is just a pointer assignment, no new object is created.


next up previous
Next: Possible extensions (optional) Up: Writing a MOOL compiler Previous: Static check of a MOOL
Marc Moreno Maza
2004-12-01