Next: Translating a MOOL program
Up: Writing a MOOL compiler
Previous: Computing symbol tables
The third step in writing a MOOL compiler
could be to perform semantic checking during parsing.
Since the syntax of the MOOL language is
very restrictive, this consists in a limited number of checks.
- When applying the rule F
id one should
check that id is a variable with an integer value.
- In the
ObjectCreation of an object of class A
the
CallingParameterList must match
the
FormalParamterList of a
NewDeclaration
of class A.
- In a
MethodCall the
CallingParameterList must match
the
FormalParamterList of the
MethodDeclaration.
- In an assignment of the form id :=
RightValue
two cases arise.
- Either id has not been initialized yet (and so has no
known type). Then id refers now to the value of
RightValue
(which may be an object or an integer).
- Or id has been initialized yet (and thus has a type)
and its type must be that of
RightValue (name equivalence).
Then id refers now to the value of
RightValue
(which may be an object or an integer).
Otherwise an error must be produced.
- In an assignment of the form
AttributeCall :=
RightValue
only one case arises.
Indeed, an attribute (even if it has not been initialized yet)
has a type.
This type must match that of
RightValue
(here again, just use name equivalence for resolving type equivalence).
Then the attribute refers now to the value of
RightValue
(which may be an object or an integer).
Otherwise an error must be produced.
Finally, observe that no overloading resolution is needed.
Next: Translating a MOOL program
Up: Writing a MOOL compiler
Previous: Computing symbol tables
Marc Moreno Maza
2004-12-01