Show a leftmost derivation step by step (each step on a single line)
for the statement: A = A + B * C using the following grammar:
<assign> --> <id> = <expr>
<expr> --> <id> + <expr> |
<id> * <expr> | <id>
<id> --> A
| B | C
Is this grammar ambiguous (Yes or No?) Justify your answer.
Does this grammar enforce the precedence of the conventional operators (Yes or No?) Justify your answer.
No, the grammar is not ambiguous.
Reason:
There are no more than one leftmost derivation or more than one rightmost derivation or more than one parse tree possible that can generate the same expression. Hence, it is unambiguous.
Yes, this grammar enforce the operator precedence of the conventional operators
Reason:
The grammar is an operator precedence grammar.
The operator precedence table for the given grammar is:
Get Answers For Free
Most questions answered within 1 hours.