2023-12-17 15:23:14 -04:00
|
|
|
.. _full-grammar-specification:
|
|
|
|
|
2008-08-03 06:47:27 -03:00
|
|
|
Full Grammar specification
|
|
|
|
==========================
|
|
|
|
|
2020-07-27 15:20:36 -03:00
|
|
|
This is the full Python grammar, derived directly from the grammar
|
|
|
|
used to generate the CPython parser (see :source:`Grammar/python.gram`).
|
|
|
|
The version here omits details related to code generation and
|
|
|
|
error recovery.
|
2008-08-03 06:47:27 -03:00
|
|
|
|
2020-07-27 15:20:36 -03:00
|
|
|
The notation is a mixture of `EBNF
|
|
|
|
<https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form>`_
|
|
|
|
and `PEG <https://en.wikipedia.org/wiki/Parsing_expression_grammar>`_.
|
|
|
|
In particular, ``&`` followed by a symbol, token or parenthesized
|
|
|
|
group indicates a positive lookahead (i.e., is required to match but
|
|
|
|
not consumed), while ``!`` indicates a negative lookahead (i.e., is
|
2022-11-07 00:55:55 -04:00
|
|
|
required *not* to match). We use the ``|`` separator to mean PEG's
|
2020-11-30 15:08:26 -04:00
|
|
|
"ordered choice" (written as ``/`` in traditional PEG grammars). See
|
|
|
|
:pep:`617` for more details on the grammar's syntax.
|
2020-07-27 15:20:36 -03:00
|
|
|
|
|
|
|
.. literalinclude:: ../../Grammar/python.gram
|
|
|
|
:language: peg
|