Chapter 5:Semantic Analysis

Type conversion

. Consider expression like x + i where x is of type real and i is of type integer

. Internal representations of integers and reals are different in a computer

- different machine instructions are used for operations on integers and reals

. The compiler has to convert both the operands to the same type

. Language definition specifies what conversions are necessary.

. Usually conversion is to the type of the left hand side

. Type checker is used to insert conversion operations: x + i _ x real+ inttoreal(i)

. Type conversion is called implicit/coercion if done by compiler.

. It is limited to the situations where no information is lost

. Conversions are explicit if programmer has to write something to cause conversion