Consider the grammar defined by the following production rules, with two operators and
Which one of the following is TRUE?
View worked solution
Answer: B
To determine the associativity of the operators and , we analyze the recursive structure of the production rules defining them:
-
Associativity of (defined by ):
The production rule is:
This is a left-recursive production because the non-terminal on the left-hand side () appears as the leftmost symbol on the right-hand side of the recursive alternative (). Left-recursion groups operands from left to right, meaning the operator is left-associative.
-
Associativity of (defined by ):
The production rule is:
This is a right-recursive production because the non-terminal on the left-hand side () appears as the rightmost symbol on the right-hand side of the recursive alternative (). Right-recursion groups operands from right to left, meaning the operator is right-associative.
Thus, is right-associative, while is left-associative.
Free practice · Your answers on this page are not saved.
