GATE 2005
March 12, 2025GATE 2005
March 12, 2025GATE 2005
Question 86
|
Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
E → number E.val = number. val |E '+' E E(1).val = E(2).val + E>sup>(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 grammar. Consider an expression 3 × 2 + 1. What precedence and associativity properties does the generated parser realize?
Equal precedence and left associativity; expression is evaluated to 7
|
|
Equal precedence and right associativity; expression is evaluated to 9
|
|
Precedence of ‘×’ 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
|
Question 86 Explanation:
First of all, it is ambiguous grammar. Hence, equal precedence and associativity. Now as Yacc resolved it with shift move we will shift until the last operator and then we will start reducing.

Hence, the answer is 9 and right associative.

Hence, the answer is 9 and right associative.
Correct Answer: B
Question 86 Explanation:
First of all, it is ambiguous grammar. Hence, equal precedence and associativity. Now as Yacc resolved it with shift move we will shift until the last operator and then we will start reducing.

Hence, the answer is 9 and right associative.

Hence, the answer is 9 and right associative.
Subscribe
Login
0 Comments