• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE-CS-2005 | Question 86

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

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments