Compiler Design and Construction - Old Questions
6. Differentiate between static and dynamic type checking. How can we carry out type checking for the following expression using syntax-directed definition?
The key difference between the static and dynamic type checking is that with static type checking, the type of variable is known at compile time (it checks the type of variable before running) while with dynamic type checking, the type of variable is known at runtime (it checks the type of variable while executing).
Type checking for the given expression using syntax-directed definition:
S → id = E { if (id.type = E.type then S.type=void else S.type = type-error }
S → if E then S1 { if (E.type = boolean then S.type = S1.type else S.type = type-error }
S → while E do S1 { if (E.type = boolean then S.type = S1.type else S.type = type-error }
S → S1;S2 { if S1.type = void and S2.type = void then S.type = void else S.type = type_error }