Simple Ambiguity problem

Mar 3, 2015 at 12:07pm
Hi guys.I have a problem about ambiguous grammer.I am working with my book myself.I saw an example grammer like this
1
2
3
    <assign>-><id>=<expr>
    <id>->A|B|C
    <expr>-> <id> + <expr> |<id> * <expr> | (<expr>) | <id>

Can I create this assignmemt A= B + C *A in terms of this grammer.?In my book, this assignment A = B * (A + C) is created in terms of this grammer and only one parse tree is created.But the assignment that I want to create causes two parse tree in anaother grammer like this

1
2
3
<assign>-><id>=<expr>
    <id>->A|B|C
    <expr>-> <expr> + <expr> |<expr> * <expr> | (<expr>) | <id>
Last edited on Mar 3, 2015 at 5:27pm
Mar 3, 2015 at 12:50pm
The second grammar is ambiguous because A = B + C * A can parsed like this:
A = <expr> * <expr>
      /\   *   A
     B + C

or like this:
A = <expr> + <expr>
      B    +   /\
             C * A

Mar 3, 2015 at 1:14pm
Can I create this assignmemt A= B + C *A in terms of first grammer?If I can create this string for the fist grammer,so first grammer should be ambigious?Am i right??
Last edited on Mar 3, 2015 at 5:14pm
Mar 3, 2015 at 7:30pm
The first grammar is not ambiguous. An expr starts with an id or a "(".
Topic archived. No new replies allowed.