Compiler Design and Construction - Old Questions
7. Write the type expressions for the following types:
a. An array of pointers to real’s, where the array
index range from 1 to 100.
b. Function whose domains are function from two characters and
whose range is a pointer of integer.
6 marks
|
Asked in 2068
a)
T→ real { T.type = real}
E → array [100, T] { if T.Type = real then T.type = array(1..100, T) else type_error() }
E→ Pointer[E1] { if (E1.type = array[100, real)) then E.type = E1.type else E.type = type-error }
b)
T→ int { T.type = int }
T →char { T.type = char}
T→ Pointer[T1] { T.type = Pointer(T1.type) }
E→ E1[E2] { if ( E2.type = (char, char) and E1.type = (char, char) → Pointer(int) then E.type = E1.type else type_error }