Question

Show that the following grammar for expressions is ambiguous and provide an alternate unambiguous grammar that...

Show that the following grammar for expressions is ambiguous and provide an alternate unambiguous grammar that defines the same set of expressions.

<expr> ::= <term> | <factor>
<term> ::= <factor> | <expr> + <term>
<factor> ::= id  | <expr> * <factor>
0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer)

If two or more parse trees or left most or right most derivations exist from single string then the grammar is ambiguous.

string is id*id

leftmost derivation 1:

<expr>::=<term>

::=<expr>*<factor>

::=<factor>*<factor>

::=id*<factor>

::=id*id

leftmost derivation 2:

<expr>::=<term>

::=<expr>*<factor>

::=<term>*<factor>

::=<factor>*<factor>

::=id*<factor>

::=id*id

unambiguous grammar is:

<expr>::=<expr>+<term>|<term>

<term>::=<term>*<factor>|<factor>

<factor>::=id

Add a comment
Know the answer?
Add Answer to:
Show that the following grammar for expressions is ambiguous and provide an alternate unambiguous grammar that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT