[Python-Dev] Python 3.0 grammar ambiguous?

Fabio Zadrozny fabiofz at gmail.com
Sun Mar 8 21:07:46 CET 2009


Hi All,

I'm trying to parse Python 3.0 following the Python 3.0 grammar from:
http://svn.python.org/projects/python/branches/py3k/Grammar/Grammar

Now, when getting to the arglist, it seems that the grammar is
ambiguous, and I was wondering how does Python disambiguate that (I'll
not put the whole grammar here, just the part that appears to be
ambiguous):

arglist: (argument ',')*
                        (argument [',']
                         |'*' test (',' argument)* [',' '**' test]
                         |'**' test
                         )

argument: test [comp_for]
test: or_test
or_test: and_test
and_test: not_test
not_test: 'not' not_test | comparison
comparison: star_expr
star_expr: ['*'] expr


So, with that construct, having call(arglist) in a format:
call(*test), the grammar would find it to be consumed in the argument
construction (because of the start_expr) and not in the arglist in the
'*' test (because the construct is ambiguous and the argument
construct comes first), so, I was wondering how does Python
disambiguate that... anyone has any pointers on it? It appears that
happened while adding PEP 3132.

Am I missing something here?

Thanks,

Fabio


More information about the Python-Dev mailing list