yacc shift/reduce conflict
-
20-06-2021 - |
سؤال
I faced conflict problem during yacc compilation.
Error message below:
24: shift/reduce conflict (shift 66, reduce 99) on '/'
state 24
arithmetic_leaf : absolute_path . (99)
absolute_path : absolute_path . '/' relative_path (102)
Code below:
arithmetic_leaf: '(' arithmetic_expression ')'
{
}
| integer_value
{
}
| real_value
{
}
| absolute_path
{
}
;
absolute_path: '/'
{
}
| '/' relative_path
{
}
| absolute_path '/' relative_path
{
}
;
relative_path: path_segment
{
}
| relative_path '/' path_segment
{
}
;
path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
{
}
| V_ATTRIBUTE_IDENTIFIER '[' V_ARCHETYPE_ID ']'
{
}
| V_ATTRIBUTE_IDENTIFIER
{
}
;
At this point, 'shift/reduce' conflict will occur.
I don't know what is the problem. How to solve this conflict?
Thanks.
المحلول
The conflict (appears to me) to be between the alternatives for absolute_path
.
It appears that a string like '/a/b
will match either the absolute_path '/' relative_path
rule, or the '/' relative_path
rule.
At least to me, it looks like you just want to eliminate one of the two. I'd probably write it as:
absolute_path: '/'
| '/' relative_path
;
Alternatively, it might make more sense to allow a relative_path
to just be an empty string, in which case, you could end up with something like:
absolute_path: '/' relative_path
;
relative_path:
| path_segment
| relative_path '/' path_segment
;
لا تنتمي إلى StackOverflow