我在 Happy(Haskell 的 Bison 等价物)中制作了一个简单的解析器,我偶然发现了这些规则中的 shift/reduce 冲突:
ClassBlock :
"{" ClassAttributes ClassConstructor ClassFunctions "}" {ClassBlock $2 $3 $4}
ClassAttributes :
{- empty -} { ClassAttributesEmpty }
| ClassAttributes ClassAttribute {ClassAttributes $1 $2}
ClassAttribute :
"[+]" Variable {ClassAttributePublic $2 }
| "[-]" Variable {ClassAttributePrivate $2 }
ClassFunctions :
{- empty -} { ClassFunctionsEmpty }
| ClassFunctions ClassFunction {ClassFunctions $1 $2}
ClassFunction :
"[+]" Function {ClassFunctionPublic $2}
| "[-]" Function {ClassFunctionPrivate $2}
ClassConstructor :
{- empty -} { ClassConstructorEmpty }
| TypeFuncParams var_identifier Params Block {ClassConstructor $1 $2 $3 $4}
TypeFuncParams :
Primitive ClosingBracketsNoIdentifier { TypeFuncParamsPrimitive $1 $2}
| class_identifier ClosingBracketsNoIdentifier { TypeFuncParamsClassId $1 $2}
| ListType {TypeFuncParamsList $1}
信息文件说明了移位/减少冲突:
ClassBlock -> "{" ClassAttributes . ClassConstructor ClassFunctions "}" (rule 52)
ClassAttributes -> ClassAttributes . ClassAttribute (rule 54)
"[+]" shift, and enter state 85
(reduce using rule 61)
"[-]" shift, and enter state 86
(reduce using rule 61)
第 61 条是这样的:
ClassConstructor :
{- empty -} { ClassConstructorEmpty }
我不确定如何解决这个问题。我尝试使用优先规则来使警告静音,但没有达到我的预期。