> That paragraph seems rather confused. I think what it might be
> trying to say is that a PEG parser allows you to write productions
> with overlapping first sets (which would be "ambiguous" for an
> LL parser), but still somehow guarantees that a unique parse tree
> is produced. The latter suggests that the grammar as a whole still
> needs to be unambiguous.

We may need to rephrase this to make it a bit more clear, but this is
trying to say that PEG grammars cannot be ambiguous in the same sense
as context-free grammars are normally said to be ambiguous. Notice that
an ambiguous grammar is normally defined (for instance here 
https://en.wikipedia.org/wiki/Ambiguous_grammar)
only for context-free grammars as a grammar with more than one possible
parse tree. In the PEG formalism as Guido explained in the previous email
there is only one possible parse tree because the parser always chooses the 
first
option.

As a consequence of this (and as a particular case of this) and as you mention, 
the
PEG formalism allows writing productions with overlapping first sets. Also, 
notice
that first sets are mainly relevant for LL(k) parsers and the like because 
those need to
*deduce* which alternative to follow given multiple choices in production while
PEG will always try in order.

In general, the argument is that because of how PEG works, it will only be one 
parse
tree and this makes the grammar "not ambiguous" under the typical definition for
ambiguity for context-free grammars (having multiple parse trees).
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4D3B2NM2JMV2UKIT6EV5Q2A6XK2HXDEH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to