Consider the following?grammar productions Assume you have an attribute E?type which can be set to either INT, BOOL. Assume that the type of an expression is set to INT if an error is detected. Assume you have a routine msg() similar to printf() that can be used to print error message. Add rules to the attribute grammar to calculate E?type for each grammar production.
Explanation / Answer
E --> CONST {E.Type = INT; } | ID {E.type = getType(ID.name); } | E1 + E2 { if(E1.type== E2.type) E.type = E1.type; else{ E.type =INT; msg(Type of E1 is not equal to typeof E2); } } | E1