简体   繁体   English

语法冲突-减少减少冲突稀疏

[英]Grammar conflict - Reduce Reduce Conflict Gold sparser

Im get a conflict reduce-reduce in the below code , ive tried almost all i ideas i came up with to solving it heres the report of the problem, this is a BNF->Gold parser conversion any ideas to solve it i would aprreciate it 我在下面的代码中减少了冲突,我尝试了我提出的几乎所有想法来解决它,这是问题的报告,这是BNF-> Gold解析器的转换,任何解决它的想法我都会感激

<Constructor> ::= <Type> '{' <SetCons_RecordCons_ArrayCons_Optional> '}'

<SetCons_RecordCons_ArrayCons_Optional> ::= <>
                                          | <SetCons>
                                          | <RecordCons>
                                          | <ArrayCons>
                !| <Type> '{' <SetCons> '}'
                !| <Type> '(' <RecordCons> '}'
                !| <Type> '(' <ArrayCons> ')'

!SetCons = SetElt {"," SetElt}  Inclui o SetElt
<SetCons> ::= <Expr>
            | <Expr> '..' <Expr>
            | <Expr> ',' <SetCons>
            | <Expr> '..' <Expr> ',' <SetCons>

!SetElt = Expr [".." Expr]
!<SetElt> ::= <Expr>
           !| <Expr> '..' <Expr>

!RecordCons = RecordElt {"," RecordElt}    inclui o recordElt
<RecordCons> ::= <Expr>
               | <Expr> <RecordCons>
               | <Expr> ',' <RecordCons>
               | Id ':=' <Expr> ',' <RecordCons>

!RecordElt = [Id ":="] Expr
!<RecordElt> ::= <Expr>
!             | Id ':=' <Expr>

!ArrayCons =  Expr {"," Expr} ["," ".."]
<ArrayCons> ::= <Expr> ',' <ArrayCons>
              | <Expr> ',' '..'
              | <Expr>

Here is the report: 这是报告:

2. Reduce-Reduce conflict for the symbol '}'

Productions in Conflict

When the parser encounters '}', more than one production can be completed (reduced):

<SetCons> ::= <Expr> •
<RecordCons> ::= <Expr> •
<ArrayCons> ::= <Expr> •

Reduce Production #1

The production below can be followed by '}' :

<SetCons> ::= <Expr> •

Because... '}' directly follows <SetCons_RecordCons_ArrayCons_Optional>.

<Constructor> ::= <Type> '{' • <SetCons_RecordCons_ArrayCons_Optional> '}' 

Reduce Production #2

The production below can be followed by '}' :

<RecordCons> ::= <Expr> •

Because... '}' directly follows <SetCons_RecordCons_ArrayCons_Optional>.

<Constructor> ::= <Type> '{' • <SetCons_RecordCons_ArrayCons_Optional> '}' 

Reduce Production #3

The production below can be followed by '}' :

<ArrayCons> ::= <Expr> •

Because... '}' directly follows <SetCons_RecordCons_ArrayCons_Optional>.

<Constructor> ::= <Type> '{' • <SetCons_RecordCons_ArrayCons_Optional> '}' 

The Gold Parser diagnosis seems to be quite detailed, and it certainly contains all the information you need. Gold Parser诊断似乎很详细,并且肯定包含您需要的所有信息。

But to put it simply, any of SetCons , RecordCons or ArrayCons can be an Expr . 简单地说,任何SetConsRecordConsArrayCons都可以是Expr So it is possible for the input to be simply: 因此,输入可能很简单:

<Type> { <Expr> }

in which case, the parser cannot know which of those three non-terminals it should reduce the Expr to. 在这种情况下,解析器无法知道应将Expr减少到这三个非终端中的哪一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM