Simple Ambiguity problem

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
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

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
The first grammar is not ambiguous. An expr starts with an id or a "(".
Topic archived. No new replies allowed.