4 ms·
> They try to sell this as a "solution" to ambiguous grammars But it is a solution... the grammar is no longer ambiguous if you define choice as giving priorit
by chrisseaton 9y ago
> They try to sell this as a "solution" to ambiguous grammars
But it is a solution... the grammar is no longer ambiguous if you define choice as giving priority to one side or the other. There's no need for scare quotes! It is a solution that removes ambiguity. There is no longer any ambiguity, and there's nothing 'vague' at all about a rule as simple and clear as this.
> but they're just ... wrong
You'll have to give a more convincing argument than that if you want to persuade people!
> It's as if Java, when resolving method overloading, arbitrarily prefered the method that's declared first in the source file, instead of refusing to compile ambiguous code, as it does now
But if you had this rule, then the code isn't ambiguous any more is it? It has a well-defined way to decide which method to use, which everyone can understand and implement.
- yxhuvud 9y agoIt is a "solution" because it becomes unobvious what language it will parse, not because it doesn't resolve the ambiguity.
- chrisseaton 9y agoI can't see why that would be the case. When I read the grammar I can see the choice operators and I know they have priority. What is unobvious about that?
- haberman 9y ago> But it is a solution... the grammar is no longer ambiguous if you define choice as giving priority to one side or the other. Sure it's no longer ambiguous to the computer. But the important question is: is it ambiguous to a human? Take the "dangling else" problem. What does this mean in C? if (a) if (b) f(); else g(); If you defined your grammar with a PEG, the answer is: whichever alternative you put first (if-with-else or if-without-else). But that answer doesn't help someone actually trying to use your language unless they go and read your PEG. What user wants to do that? Worse, it keeps language designers from being aware when they accidentally put gotchas like this into their languages. The PEG tools can't warn you, because to a PEG tool there is no problem. As a real-world example of this, it was not discovered that ALGOL 60 had a "dangling else" ambiguity until the language had already been published in a technical report. A CFG-based tool could have warned the designers about the ambiguity, but with PEG-based tools you are designing blind.
- chrisseaton 9y agoYour example seems to support my argument, not yours! Dangling else's are solved by formally expressing a fixed priority in the grammar. > unless they go and read your PEG Well yes they need to read the documentation for the language... how else were they managing to write a program in it? How is it any difference from having to read the documentation to understand the precedence of different operators?
- haberman 9y agoDangling else is solved by changing the definition of the language. Newer languages don't have the dangling else problem, because we learned the hard way in the 60s how to avoid it. PEG-based tools invite more mistakes like this, because they can prevent the discovering of ambiguities until it is too late to fix them. Yes, operator precedence is another example of ambiguity: we live with it because infix math is useful enough that we live with the fact that you have to learn the precedence rules. But with PEG-based tools, you can accidentally introduce ambiguities that might be easy to avoid if you just knew about them at the design stage. I would never design a language with PEG-based tools, because I would have no idea where I might be introducing pointless ambiguity.
- chrisseaton 9y ago> prevent the discovering of ambiguities But there are no ambiguities to discover if you use a PEG! A language grammar defined using PEG cannot be ambiguous!
- haberman 9y agoIt's very strange that you keep returning to this. "Dangling else" is a problem regardless of how you write down your grammar or implement your parser. It's like sweeping a mound of dirt under the rug and then saying "by definition, there is no dirt on the rug!"
- 9y ago