Is there a set way to determine ambiguity in a grammar?
Asked Answered
C

1

6

We are learning about ambiguity in class, and the following grammar was given as an example of an ambiguous grammar. I just am not seeing how it is ambiguous. Is there a set pattern or method people use to determine ambiguity or is it just like a logic puzzle where you have to work through combinations to find an ambiguous sentence in the grammar? The examples I've read online mostly given the ambiguous sentence already, but how do you find that sentence in the first place? I'd appreciate any help, thank you.

< stmt_list> ==> < stmt>

               | < stmt> ; < stmt_list>

< var> ==> A | B | C

< stmt> ==> < var> + < var>

               | < var> - < var>

               | < var>
Chanson answered 2/3, 2013 at 15:25 Comment(4)
I made mistake in my answer thats why I remove you present grammar is not ambiguous.Nashbar
@GrijeshChauhan I see. Thank you. This is very confusing because our professor told us this was ambiguous.Chanson
But your grammar is not correct for the purpose of math expression too :( view this example for correct #14555252Nashbar
This must have been asked upteem times, but @DPenner's very concise answer makes this Q&A a keepr.Integrand
L
2

In general, determining whether a grammar is ambiguous or not is undecidable. So yes, finding an ambiguous sentence in a grammar reduces to a very difficult logic puzzle. Solving specific cases and finding heuristics is an active area of research though. Here is a fairly good tool at finding ambiguity: http://www.brics.dk/grammar/. The webpage includes a link to a paper explaining how it works, though honestly, that goes over my head.

Livengood answered 3/3, 2013 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.