Chapter 5:Semantic Analysis

Narrowing the set of possible types

 

E' E E'.types = E.types
  E.unique = if E'.types=={t} then t
 

else type_error

   
E id E.types = lookup(id)
   
E E1 (E2 ) E.types = { t | there exists an s in E2 .types
 

and s t is in E1 .types}

  t = E.unique
  S = {s | s ε E2.types and (s t)ε E1.types}
  E 2 .unique = if S=={s} then s else type_error
  E1 .unique = if S=={s} then s t else type_error

In E' E, it is checked whether we have finally narrowed down only one type. If not then type error is generated since Ada does not tolerate any type ambiguity in complete expressions.

In E E1 (E 2 ), you can see that it is made sure that E1 and E2 have only one unique type and they are such that they lead to only one unique type for E.