Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.0 grammar is ambiguous with the addition of star_expr #49710

Closed
fabioz mannequin opened this issue Mar 9, 2009 · 2 comments
Closed

Python 3.0 grammar is ambiguous with the addition of star_expr #49710

fabioz mannequin opened this issue Mar 9, 2009 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@fabioz
Copy link
Mannequin

fabioz mannequin commented Mar 9, 2009

BPO 5460
Nosy @fabioz, @benjaminp

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 = None
closed_at = <Date 2009-09-27.02:46:06.040>
created_at = <Date 2009-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 = <Date 2009-09-27.02:46:06.010>
user = 'https://github.com/fabioz'

bugs.python.org fields:

activity = <Date 2009-09-27.02:46:06.010>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-09-27.02:46:06.040>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2009-03-09.19:00:12.000>
creator = 'fabioz'
dependencies = []
files = []
hgrepos = []
issue_num = 5460
keywords = []
message_count = 2.0
messages = ['83395', '93167']
nosy_count = 2.0
nosy_names = ['fabioz', 'benjamin.peterson']
pr_nums = []
priority = 'high'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue5460'
versions = ['Python 3.0', 'Python 3.1']

@fabioz
Copy link
Mannequin Author

fabioz mannequin commented 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

@fabioz fabioz mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Mar 9, 2009
@benjaminp
Copy link
Contributor

Fixed in r75080.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant