We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12
WCU
College of Engineering and Technology
Dep’t : Computer Science
Course: Compiler Design
Chapter 4: TYPE CHECKING
Instructor: Agegnehu Ashenafi (MSc.)
Chapter 4: TYPE CHECKING Type Checking done by a compiler is said to be static, while checking done when the target program runs is termed dynamic. In principle, any check can be done dynamically. A compiler must check that the source program follows both the syntactic and semantic conventions of the source language. This checking, called static checking (to distinguish it from dynamic checking during execution of the target program), ensures that certain kinds of programming errors will be detected and reported. There are 4-examples of static checks include: 5.1. Type Systems b) Type checking of Statement 5.2. Specification of type checking • In this section, we specify a type checker for a simple language In which the type of each identifier must be declared before the identifier is used. The type checker is a translation scheme that synthesizes the type of each expression from the types of its sub expressions. The type checker can handle arrays, pointers, statements, and functions. 5.3. Equivalence of type expression "If two type expressions are equal then return a certain type else return type error." It Is therefore important to have a precise definition of when two type expressions are equivalent+ Type equivalence implemented by a specific compiler can often be explained using the concepts of structural and name equivalence. a) Structural Equivalence of Type Expressions:- type expressions are built from basic types and constructors, a natural notion of equivalence between two type expressions is structural equivalence. i .e., two expressions are either the same basic type , or are formed by applying the same constructor to structurally equivalent types. That is, two type expressions are structurally equivalent if and only if they are identical. • For example, the type expression integer is equivalent only to integer because they are the same basic type. • Similarly, pointer (integer) is equivalent only to pointer (integer) because the two are formed by applying the same constructor pointer to equivalent types, Thank You ! …Question ?