Skip to content

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

Closed

Description

@fabioz
mannequin
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']

Activity

  1. fabioz commented on Mar 9, 2009

    fabiozmannequin
    MannequinAuthor

    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

  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-featureA feature request or enhancement
    on Mar 9, 2009
  3. benjaminp commented on Sep 27, 2009

    @benjaminp
    Contributor

    Fixed in r75080.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions