6.3 Type Equivalence

While type checking, we will have to check equivalence of types. For simple types, it is a matter of merely comparing type(np1) with type(np2), where np1 and np2 are pointers to nodes representing the two program components.

When we have complex data types, we need to ensure that the two type trees have exactly the same structure. We do this by a int tree_comp(Node *np1, Node *np2) function:

int tree_comp(Node *np1, Node *np2){
   if(type(np1) == type(np2)){
       if(type(np1) < TREE) return 1;
       retrun tree_comp_rec(ttree(np1), ttree(np2));
   }
   return 0;
}
int tree_comp_rec(Node *np1, Node *np2){
   return tree_comp(np1, np2);
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.119