Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following?grammar productions Assume you have an attribute E?type w

ID: 3612244 • Letter: C

Question

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
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote