As an example too well-known to actually occur, suppose you parse “if x then if y then x else z” with the else clause associated to the first if statement, because that’s just how you happened to write the parser. It’s not ambiguous, but your users won’t be happy when they find out the unambiguous rule.
But there are no ambiguities in recursive descent! They won't discover them because... they don't exist! It's literally impossible.
> As an example too well-known to actually occur, suppose you parse...
Great example - and the good thing about recursive descent means it's impossible to write this ambiguously - you must prefer one or the other.
> It’s not ambiguous
Correct. So why are you telling me the problems of ambiguity?
> but your users won’t be happy when they find out the unambiguous rule
Why won't they be happy? You can tell them exactly how their code is going to be parsed. I thought ambiguities was bad but now you're complaining about ambiguity as well?!
The question is, did the designer resolve them deliberately or accidentally? And were they resolved in an ergonomic way?
The grammar fragment “expr :: IF expr THEN expr ELSE expr” is ambiguous. If I write a statement like the example, I expect (from 60 years of language tradition and simple ergonomics) a language author to choose to resolve that ambiguity by associating an ELSE with the nearest IF. Telling your puzzled users “it’s not ambiguous, it always goes with the farthest IF!” isn’t going to make them happier. It also won’t work to say “well, + has higher precedence than /, but that’s OK, it always does that”. Those are just bugs in the language design caused by a bad resolution of ambiguity.
If you use a tool to flag the ambiguities in your grammar, then you can be sure all the resolutions in your parser are deliberate and not accidental.
Not if they started with a grammar that didn't have any ambiguity in the first place.
I think you're coming from the angle that you always start with a CFG, resolve ambiguity, then write a parser.
Imagine that I never write a CFG for my language. No CFG exists! Instead - I start by writing a PEG, and then I write a recursive descent parser from that. At no point in this process have I had to resolve ambiguity. I didn't start with an ambiguous CFG and then write a PEG from it. I started with a PEG. It's never been ambiguous, and never will be ambiguous. There's no ambiguity.
> The grammar fragment “expr :: IF expr THEN expr ELSE expr” is ambiguous.
Right.... but I wouldn't write that because I'm not starting with a CFG I'm starting with a PEG.
> Telling your puzzled users “it’s not ambiguous, it always goes with the farthest IF!” isn’t going to make them happier.
I can't understand this - if I give them a simple well-defined rule that tells them what the code means they'll be happy. What do you think they'd want instead? No rule? A badly defined rule?
This can happen even if you write a formal specification.
I don't know where 'codify your bad assumptions' comes into it? What assumptions? How are they codified without you knowing?