4) The following grammar applies + and * operators to integer and real constants
ID: 646026 • Letter: 4
Question
4) The following grammar applies + and * operators to integer and real constants. The result of adding two integers is type integer, otherwise the result is type real. A number (T) with a decimal point is real, otherwise is integer. Write a syntax directed definition for this grammar to determine the type of each subexpression; if an operation involves mixed integer and real values, convert integer values to real. Write semantic actions to output 3-addres code. Assume the following operators: (If you believe you need any additional 3-address operators, you may add them to the above list). t).Explanation / Answer
Directed definition for a grammer of arithematic expression:
Expr-> expr+term|term
term-> term*factor|factor
factor-> id|num|(expr)
i.e. expr is a string of terms seperated by + and -.
A term is a string of factors separed by * and /.
A factor is a single operand or an expression wrapped.
_______________________________________________________________________
Semantic Analysis
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.