Author dalke
Recipients dalke
Date 2008-02-05.00:19:49
SpamBayes Score 0.0795331
Marked as misclassified No
Message-id <1202170790.58.0.28997794645.issue2009@psf.upfronthosting.co.za>
In-reply-to
Content
I wrote a translator from the CFG used in the Grammar file into a form for PLY.  I 
found one problem with

varargslist: ((fpdef ['=' test] ',')*
              ('*' NAME [',' '**' NAME] | '**' NAME) |
              fpdef ['=' test] (',' fpdef ['=' test])* [','])

This grammar definition is ambiguous until the presence/lack of a "*".  PLY 
complains:

state 469

    (28) varargslist -> fpdef EQUAL test COMMA .
    (32) varargslist_star -> fpdef EQUAL test COMMA .
    (35) varargslist_star3 -> COMMA . fpdef
    (36) varargslist_star3 -> COMMA . fpdef EQUAL test
    (39) fpdef -> . NAME
    (40) fpdef -> . LPAR fplist RPAR

  ! shift/reduce conflict for NAME resolved as shift.
  ! shift/reduce conflict for LPAR resolved as shift.

    RPAR            reduce using rule 28 (varargslist -> fpdef EQUAL test COMMA .)
    COLON           reduce using rule 28 (varargslist -> fpdef EQUAL test COMMA .)
    STAR            reduce using rule 32 (varargslist_star -> fpdef EQUAL test 
COMMA .)
    DOUBLESTAR      reduce using rule 32 (varargslist_star -> fpdef EQUAL test 
COMMA .)
    NAME            shift and go to state 165
    LPAR            shift and go to state 163

  ! NAME            [ reduce using rule 32 (varargslist_star -> fpdef EQUAL test 
COMMA 
.) ]
  ! LPAR            [ reduce using rule 32 (varargslist_star -> fpdef EQUAL test 
COMMA 
.) ]

    fpdef                          shift and go to state 515



My fix was to use this definition when I did the translation.

varargslist: ((fpdef ['=' test] (',' fpdef ['=' test])* 
                   (',' '*' NAME [',' '**' NAME] | ',' '**' NAME | [','])) |
              ('*' NAME [',' '**' NAME]) |
              ('**' NAME))


So far I've not found a functional difference between these two definitions, and 
the only change to ast.c is to update the comment based on this section.

By making this change it would be easier for the handful of people who write 
parsers for Python based on a yacc-like look-ahead(1) parser to use that file more 
directly.
History
Date User Action Args
2008-02-05 00:19:51dalkesetspambayes_score: 0.0795331 -> 0.0795331
recipients: + dalke
2008-02-05 00:19:50dalkesetspambayes_score: 0.0795331 -> 0.0795331
messageid: <1202170790.58.0.28997794645.issue2009@psf.upfronthosting.co.za>
2008-02-05 00:19:49dalkelinkissue2009 messages
2008-02-05 00:19:49dalkecreate