[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Strange behavior
From: |
Laurent Deniau |
Subject: |
Strange behavior |
Date: |
Thu, 25 Mar 2004 12:35:48 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3 |
I am using Bison 1.35 and 1.875 to parse the ISO C99 grammar and I found
a strange behavior on a very simple case:
If I use the rule:
direct_abstract_declarator
: '(' abstract_declarator ')'
| direct_abstract_declarator_opt '[' assignment_expression_opt ']'
| direct_abstract_declarator_opt '[' '*' ']'
| '(' parameter_type_list_opt ')'
| direct_abstract_declarator '(' parameter_type_list_opt ')'
;
I have only one shift/reduce conflict for all the grammar (the IF ELSE
one). But if I use the rule
direct_abstract_declarator
: '(' abstract_declarator ')'
| direct_abstract_declarator_opt '[' assignment_expression_opt ']'
| direct_abstract_declarator_opt '[' '*' ']'
| direct_abstract_declarator_opt '(' parameter_type_list_opt ')'
;
I have three shift/reduce conflicts where in both cases the optional
rules are all defined by:
THE_RULE_opt
: /* empty */
| THE_RULE
;
So while as far as I know
| '(' parameter_type_list_opt ')'
| direct_abstract_declarator '(' parameter_type_list_opt ')'
and
| direct_abstract_declarator_opt '(' parameter_type_list_opt ')'
should be equivalent, the second rule introduces two new shift/reduce
conflicts...
The good point is that the default behavior of Bison make the conflicts
not important since they are correctly reduced (in the first case, only
the $default reduce appear):
State 253 conflicts: 1 shift/reduce
State 297 conflicts: 1 shift/reduce
state 253
168 abstract_declarator: pointer_opt . direct_abstract_declarator
'(' shift, and go to state 313
'(' [reduce using rule 233 (direct_abstract_declarator_opt)]
$default reduce using rule 233 (direct_abstract_declarator_opt)
direct_abstract_declarator go to state 314
direct_abstract_declarator_opt go to state 315
state 297
145 declarator: pointer_opt . direct_declarator
168 abstract_declarator: pointer_opt . direct_abstract_declarator
IDENTIFIER shift, and go to state 39
'(' shift, and go to state 336
'(' [reduce using rule 233 (direct_abstract_declarator_opt)]
$default reduce using rule 233 (direct_abstract_declarator_opt)
identifier go to state 70
direct_declarator go to state 71
direct_abstract_declarator go to state 314
direct_abstract_declarator_opt go to state 315
Of course, the problem appears only in the full grammar, not in short
minimalist example and it appears only for that rule while I am using
the same _opt substitution mechanism everywhere (18 _opt rules). I can
provide the file of the full grammar if it helps.
Regards,
ld.
- Strange behavior,
Laurent Deniau <=