Direction: Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar production.
E → number | E.val = number.val |
| E ‘+’ E | E(1).val = E(2).val + E(3).val |
| E ‘×’ E | E (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 associativity properties does the generated parser realize?
-
- Equal precedence and left associativity; expression is evaluated to 7
- Equal precedence and left associativity; expression is evaluated to 9
- Precedence of ‘x’ is higher than that of ‘+’ and both operators are left associative; expression is evaluated to 7
- Precedence of ‘+’ is higher than that of ‘×’ and both operators are left associative; expression is evaluated to 9
- Equal precedence and left associativity; expression is evaluated to 7
Correct Option: B
The grammar has equal precedence and it is also ambiguous. Since LALR(1) parser prefer shift over reduce so + operation will be executed here before). 2 + 1 = 3 & 3 #3 = 9 also the operators are right associative. Hence (b) is correct option.