[New-bugs-announce] [issue2009] Grammar change to prevent shift/reduce problem with varargslist
Andrew Dalke
report at bugs.python.org
Tue Feb 5 01:19:50 CET 2008
New submission from Andrew Dalke:
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.
----------
components: None
messages: 62055
nosy: dalke
severity: minor
status: open
title: Grammar change to prevent shift/reduce problem with varargslist
type: rfe
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2009>
__________________________________
More information about the New-bugs-announce
mailing list