wiz-icon
MyQuestionIcon
MyQuestionIcon
3343
You visited us 3343 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
Enumber E.val=numbe.val
E'+'E E(1).val=E(2).val+E(3).valE '×'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 right associativity; expression is evaluated to 9
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
Precedence of '×' is higher than that of '+', and both operators are left associative; expression is evaluated to 7
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Equal precedence and left associativity; expression is evaluated to 7
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Precedence of '+' is higher than that of '×', and both operators are left associative; expression is evaluated to 9
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A Equal precedence and right associativity; expression is evaluated to 9
SR conflict is resolved in favour of shift. All operators are shifted and evaluated from right end, because × and + have equal precedence.
Hence, × and + follows right associatively.

3 × 2 + 1 = 3 × 3 = 9

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Multiplication of Matrices
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon