0

在下面的代碼中,我得到了一個衝突reduce-reduce,我嘗試了幾乎所有我想出來解決它的問題,繼承人問題報告,這是一個BNF-> Gold解析器轉換任何想法解決它,我aprreciate它語法衝突 - 減少衝突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> 

下面是報告:

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> '}' 

回答

0

黃金分析器診斷似乎是相當詳盡,也肯定包含了所有你需要的信息。

但簡而言之,SetCons,RecordConsArrayCons中的任何一個都可以是Expr。因此,它是可能的輸入是簡單的:

<Type> { <Expr> } 

在這種情況下,分析器無法知道哪個那些三無終端應該減少Expr來。