Skip to content
Related Articles

Related Articles

Improve Article
GATE | GATE-CS-2005 | Question 86
  • Last Updated : 13 Sep, 2014

Consider the following expression grammar. The seman­tic 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(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?
(A) Equal precedence and left associativity; ex­pression is evaluated to 7
(B) Equal precedence and right associativity; ex­pression is evaluated to 9
(C) Precedence of ‘×’ is higher than that of ‘+’, and both operators are left associative; expression is evaluated to 7
(D) Precedence of ‘+’ is higher than that of ‘×’, and both operators are left associative; expression is evaluated to 9


Answer: (B)

Explanation: Answer is B as the productions belong to the same non-terminal and since YACC resolves by shift over reduce, the associativity will be right associative.


Quiz of this Question

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :