Bora Kurucu
Bora Kurucu

Reputation: 31

Can a BNF grammar that does not follow operator associativity and precedence rules be considered as an unambiguous grammar?

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?

Upvotes: 0

Views: 251

Answers (2)

Michael Dyck
Michael Dyck

Reputation: 2438

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.

Upvotes: 1

rici
rici

Reputation: 241771

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

Upvotes: 1

Related Questions