next up previous
Next: Overloading of Functions and Operators Up: Compiler Theory: Type Checking Previous: Type Equivalence

Type Conversions

Type Conversions can be From the point of view of type checking, Coercions

Example 1   Let us extend the set of expression constructs of the language from the previous section
T $ \longmapsto$ $ \bf real$
E $ \longmapsto$ $ \bf num . num$.
E $ \longmapsto$ E $ \bf op$ E
The translation scheme for these new rules are:
T $ \longmapsto$ $ \bf real$ { T.type := $ \bf real$ }
E $ \longmapsto$ $ \bf num . num$ { E.type := $ \bf real$ }
E $ \longmapsto$ E1 $ \bf op$ E2 { E.type := if E1.type = $ \bf integer$ and E2.type = $ \bf integer$
then $ \bf integer$
elseif E1.type = $ \bf real$ and E2.type = $ \bf real$
then $ \bf real$
elseif E1.type = $ \bf integer$ and E2.type = $ \bf real$
then $ \bf real$
elseif E1.type = $ \bf real$ and E2.type = $ \bf integer$
then $ \bf real$
else $ \bf type\_error$ }


next up previous
Next: Overloading of Functions and Operators Up: Compiler Theory: Type Checking Previous: Type Equivalence
Marc Moreno Maza
2004-12-02