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

时间:2014-05-08 16:04:06

标签: context-free-grammar bnf gold-parser reduce-reduce-conflict

我在下面的代码中得到了一个冲突reduce-reduce,我尝试了几乎所有的想法,我想出来解决它继承问题的报告,这是一个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>

以下是报告:

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

1 个答案:

答案 0 :(得分:0)

Gold Parser诊断似乎非常详细,它肯定包含您需要的所有信息。

但简单地说,SetConsRecordConsArrayCons中的任何一个都可以是Expr。因此,输入可能只是:

<Type> { <Expr> }

在这种情况下,解析器无法知道它应该将Expr减少到哪三个非终端。