You are on page 1of 5

CSCI 435 Compiler Design

Week 9 Class 3
Section 6.1.2 to 6.1.3
(449-460)
Ray Schneider

9.3.1

CSCI 435 Compiler Design

Topics of the Day

Type Checking

The Type Table


Type Equivalence
Coercions
Casts and Conversions
Kind Checking

Conclusion of Context Handling for imperative


and object-oriented languages

9.3.2

CSCI 435 Compiler Design

Type Checking

we've seen that looking up an identifier leads to


a declaration information record which contains
the properties of the object identified
most obvious property is the KIND of the object

ex. constant, variable, routine, type, module, ...


first step in checking the proper use of the identifier
is to check this kind information which is mostly
trivial

Some Kinds which specify objects that involve


values (constants, variables, routines) may be
subject to complicated and intricate rules

these values belong to TYPES


TYPE CHECKING is not at all trivial

CSCI 435 Compiler Design

9.3.3

Type Checking 2

Type checking is involved in large parts of the


annotated syntax tree (AST)
Examples:

language rules usually specify types which can be


combined with particular operators
rules for formal and actual parameters in a routine call
assignment of an expression value to a variable
restricts the allowed types for the expression

Implementation of Type information in a


compiler has to be implemented so that checks
can be performed conveniently
9.3.4

CSCI 435 Compiler Design

Type Declarations

Types are usually introduced by name in Type


Declarations

TYPE Int_Array = ARRAY[Integer 1..10] OF Integer;


defines the type Int_Array

Types may also be introduced ANONYMOUSLY

VAR a: ARRAY [Integer 1..10] OF Real;


Anonymous types don't have a name in the source
program
the compiler has to use its imagination to invent a unique
name like #type01_in_line_35, declaration of a
TYPE #type01_in_line_35=ARRAY[Integer 1..10]OF Integer
VAR a: #type01_in_line_35
9.3.5

CSCI 435 Compiler Design

You might also like