Chapter 5:Semantic Analysis

Efficient implementation

. Bit vectors can be used to used to represent type expressions. Refer to: A Tour Through the Portable C Compiler: S. C. Johnson, 1979.

Type expression encoding
char 000000 0001
function( char ) 000011 0001
pointer( function( char ) ) 000111 0001
array( pointer( function( char) ) ) 100111 0001

This representation saves space and keeps track of constructors

How to efficiently implement Structural type checking? One Possible Approach is decided in the slide which maintains a bit vector for each type expression. Drawbacks: First, notice that each Type Constructor is described as a unary operator/function. For example type contractor "function(t)" just says that the return type of the function is of type t.

The types or the number of arguments of the function are kept some where else, i.e. not a part of the type system. If the bit patterns for two types are same then the two types are said to be structurally same. Thus the two functions

a) char getFirst(char *string) // returns the first character of the string

b) char getPosition(char *string, int p) // returns the p'th character of the string

will be same because they are both defined by function(char), i.e., the same bit vector.

Similar is the case with Array construct where the index range is not specified in the construct. Two structurally equivalent types (defined by the function in prev. slide) are guaranteed to have same bit vector representation. However two structurally different types can have the same bit vector representation. Thus this type system is a weaker system.