Syntax Analysis15

0. Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
E → numberE.val = number.val
 | E '+' EE(1).val = E(2).val + E(3).val
 | E '×' EE(1).val = E(2).val × E(3).val;
Assume the conflicts in Part (a) of this question are resolved and an LALR (1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 x 2 + 1. What precedence and associativity properties does the generated parser realize?

  • Option : C
  • Explanation :
    With look ahead, we would prefer to shift because the look ahead has higher precedence than X over + and both operation are left associative. So expression 3 x 2 + 1 = 6 + 1 = 7 will be evaluated.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *