A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

Discussion Forum

Que. 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:Equal precedence and right associativity; ex­pression is evaluated to 9
Confused About the Answer? Ask for Details Here
Know Explanation? Add it Here

Similar Questions: