3 ms·
> people think they can get away from the complexities of grammars because there are no ambiguities when you express them using PEGs. This is not true: the ambi
by chrisseaton 5y ago
> people think they can get away from the complexities of grammars because there are no ambiguities when you express them using PEGs. This is not true: the ambiguities are still there
It's literally impossible to write a PEG with an ambiguity. So I don't know what you mean?
- HelloNurse 5y agoAmbiguities in the intended language aren't literally "still there" in the PEG, but realistically they are "still there" as a source of problems: naive PEGs can remove ambiguities incorrectly in less than obvious ways, and figuring out what's wrong can be more difficult than hitting a brick wall with other parsing approaches.
- frabert 5y agoJust because the PEG doesn't have ambiguities doesn't mean the grammar you meant to recognize doesn't have one. What I mean is: PEGs give you a false sense of confidence by making you feel like you solved all your grammar's issues. In reality, you need to think really carefully about what your PEG is doing, because it's not going to warn you. As you said, PEGs are never ambiguous.
- chrisseaton 5y agoWell yeah if the grammar you wrote doesn't match what you intended to write then it's not going to work. Not sure how that's saying anything useful though? If you write the wrong grammar with any parsing system it's also not going to work.
- frabert 5y agoMost other parser generator systems give you indication that what you're writing is probably wrong, by stating e.g. that a grammar is ambiguous. S := A '+' A | A '*' A A := ... If you do that in most PEG systems I've tried, you're just going to get the wrong result with no indication of what might have gone wrong, unless you know where to look.
- chrisseaton 5y agoBut that's the point - other parsing systems let you design an ambiguous language and then tell you about it. PEGs don't let you design an ambiguous language in the first place. Unambiguous by construction.