You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python 3.0 grammar is ambiguous with the addition of star_expr #49710
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2009-09-27.02:46:06.040>created_at=<Date2009-03-09.19:00:12.000>labels= ['interpreter-core', 'type-feature']
title='Python 3.0 grammar is ambiguous with the addition of star_expr'updated_at=<Date2009-09-27.02:46:06.010>user='https://github.com/fabioz'
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 star_expr) and not in the arglist in the
'*' test.
Python seems to be lucky in this because it seems to be getting in the
correct choice, when that's not really possible from the grammar --
maybe it tries the 2nd construct before the 1st and succeeds because of
that? It seems to me that this could actually be a bug in the Python
grammar generator.
It doesn't seem possible to disambiguate that without semantic actions
later on, but the grammar could be changed to disambiguate that.
I've used the constructs below in a JavaCC grammar successfully (and I
think Python could use the same constructs):
Activity
fabioz commentedon Mar 9, 2009
Note: A discussion related to this bug was raised on:
http://mail.python.org/pipermail/python-dev/2009-March/086939.html
The following constructs are ambiguous in the Python 3.0 grammar:
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 star_expr) and not in the arglist in the
'*' test.
Python seems to be lucky in this because it seems to be getting in the
correct choice, when that's not really possible from the grammar --
maybe it tries the 2nd construct before the 1st and succeeds because of
that? It seems to me that this could actually be a bug in the Python
grammar generator.
It doesn't seem possible to disambiguate that without semantic actions
later on, but the grammar could be changed to disambiguate that.
I've used the constructs below in a JavaCC grammar successfully (and I
think Python could use the same constructs):
expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
testlist_star_expr: (test|star_expr) (',' test|star_expr)* [',']
star_expr: '*' expr
benjaminp commentedon Sep 27, 2009
Fixed in r75080.