OT: CFGs vs PEGs?
Nick Sabalausky
a at a.a
Tue Jul 1 11:24:13 PDT 2008
"Manfred_Nowak" <svv1999 at hotmail.com> wrote in message
news:g4c6ik$2jdi$1 at digitalmars.com...
> Nick Sabalausky wrote:
>
>> opinions on contex-free grammars versus parsing expression grammars?
>
> I have looked into PEG's---and no, I wouldn't trust my life to any
> machine wherein a PEG-based lexer/parser runs.
>
> This is because their precedence based behaviour will hide ambiguities
> and make them ill-conditioned: tiny changes in the grammar may sum up
> to huge changes in behaviour.
>
> Quick to set up and a nightmare for maintenance.
>
> -manfred
I see. That hadn't occurred to me, but I think I can understand why that's
the case.
As far as more technical differences, from what I've seen, it sounds like
the main difference between the two is that a PEG is basically like a CFG
except that (using a contrived example):
A <- B | C
With a CFG, if both B and C match, then that's considered an ambiguity
error, whereas with a PEG, if both B and C match, then it's automatically
disambiguated by automatically using B. As I understand it, that seems to be
the primary difference and all the other differences are basically just
consequences of that. Is that right, or is there more to it?
(Also, if that's the case, it sounds like there wouldn't be much of a
performance difference between equivilent PEG-based and CFG-based
compilers?)
More information about the Digitalmars-d
mailing list