Questions

  1. The following grammar defines lists of lists of literals. The interpretation of symbols is that same as that for the type grammar given in class (see type slides) with the addition of the type LIST that indicates a list of elements of the type T that follows:
    P --> D ; E
    D --> D ; D | id : T
    T --> list of T | char | integer
    E --> ( L ) | literal | num | id
    L --> E , L | E
    
    Write translation rules to determine the types of expressions (E) and lists (L).
  2. Use the translation scheme for the types as given in class (similar grammar to that of previous question) to compute the types of the following program fragments. Show the types at each node of the parse tree.
    a)  c: char; i: integer
        c mod i mod e
    
    b) p : ^ integer; a: array[10] of integer;
       a[p^]
    
    c) f: integer --> boolean
       i: integer; j: integer; k: integer;
       while F(i) do
         k := i;
         i := j mod i;
         j := k;
    

Solutions