parse tree has symbols not in the grammar?

Terry Reedy tjreedy at udel.edu
Wed Apr 27 02:48:51 EDT 2005


"Chad Whitacre" <chad at zetaweb.com> wrote in message 
news:d4n2c7$sj1$1 at sea.gmane.org...
> I've been playing around with the parser module, and based on the 
> documentation I would expect all symbols in a parse tree to be part of 
> the grammar.[1] For example, I find this line in the symbol module docs:
>
>   Refer to the file Grammar/Grammar in the Python distribution for the
>   definitions of the names in the context of the language grammar.[2]
>
> However, the program below gives me a human-readable parse tree (also 
> below) that contains symbols that don't seem to be in the grammar, e.g., 
> small_stmt, expr_stmt, factor. Is my expectation wrong?

Did you not find them in grammar.txt, which you referenced, or 
Grammar/Grammar is the source, which you did not.  Guido has said that the 
grammar in the ref manual, meant for human consumption, is equivalent to 
but not quite the same as the grammar used to generate the parser, which 
has to meet LL1 constraints.

> [1] http://python.org/doc/ref/grammar.txt
> [2] http://python.org/doc/lib/module-symbol.html

Terry J. Reedy






More information about the Python-list mailing list