0
votes

Consider this BNF grammar:

<assign> = <id> = <expr>
<id> = A|B|C
<expr> = <id> + <expr>|<id> * <expr>|(<expr>)|<id>

This grammar is not ambiguous, since only one parse tree can be drawn for a statement.However, this clearly does not follow operator presedence rules.Operators *,+,() have the same precedence.Is this grammar unambiguous, or is it only not ambiguous? If it is unambigious, so a grammar can be unambigious without following the operator associativity and precedence rules,is that true?

2
Just because a grammar is unambiguous does not mean that it is not broken.Chris Dodd

2 Answers

1
votes

"Unambiguous" and "not ambiguous" mean the exact same thing, which is that there is only one possible interpretation. That it is not the interpretation you expect is not relevant.

0
votes

Is this grammar unambiguous?

Yes.

So a grammar can be unambigious without following the operator associativity and precedence rules,is that true?

Yes. Operator associativity and precedence are conventions from mathematics and programming languages. Ambiguity, or lack thereof, has nothing to do with whether a grammar conforms to those conventions.