野牛:冲突转移/减少

时间:2020-05-07 09:04:59

标签: parsing grammar bison shift-reduce-conflict

我正在尝试为一种组合语言创建一个解析器,并且在这一点上已经完成了很多工作(我有一些测试文件,它可以完美地解析它们)。问题是:我有13个移位/减少冲突,但我不知道如何解决。

我查看了.output文件,结果发现所有冲突都处于相同状态:

@Test
fun tt() {
    a= spy(A())
    a.execute()
    verify(a).processList(check {
        print(it)
    })
}   

class A {

    fun execute() {
        list = getList()
        processList(list)
    }

    fun getList() = listOf(1, 2, 3)

    fun processList(list: List<Int>) {
          /// process   
    }
} 

(状态169冲突:13移位/减少)

这是状态169中语法的一部分:(我认为名称不重要,因此我不会翻译,如果有人认为语法的其他部分相关,请告诉我,但这确实是长)。

Estado 169 conflictos: 13 desplazamiento(s)/reducción(ones)

这是状态169的输出信息(我在下面进行了快速翻译,以免翻译整个块):

instruccion: instruccion instruccion                    { printf("\tREGLA: instruccion -> instruccion instruccion\n"); }
           | instruccion_asignacion                     { printf("\tREGLA: instruccion -> instruccion_asignacion\n"); }
           | instruccion_devolver                       { printf("\tREGLA: instruccion -> instruccion_devolver\n"); }
           | instruccion_llamada                        { printf("\tREGLA: instruccion -> instruccion_llamada\n"); }
           | instruccion_si                             { printf("\tREGLA: instruccion -> instruccion_si\n"); }
           | instruccion_casos                          { printf("\tREGLA: instruccion -> instruccion_casos\n"); }
           | instruccion_bucle                          { printf("\tREGLA: instruccion -> instruccion_bucle\n"); }
           | instruccion_interrupcion                   { printf("\tREGLA: instruccion -> instruccion_interrupcion\n"); }
           | instruccion_lanzamiento_excepcion          { printf("\tREGLA: instruccion -> instruccion_lanzamiento_excepcion\n"); }
           | instruccion_captura_excepcion              { printf("\tREGLA: instruccion -> instruccion_captura_excepcion\n"); }
           | ';'                                        { printf("\tREGLA: instruccion -> ;\n"); }
           | error  ';'                                 {yyerrok;}
;
estado 169

  114 instruccion: instruccion . instruccion
  114            | instruccion instruccion .

    error          desplazar e ir al estado 74
    CASOS          desplazar e ir al estado 75
    DEVOLVER       desplazar e ir al estado 76
    LANZA          desplazar e ir al estado 77
    MIENTRAS       desplazar e ir al estado 78
    PARA           desplazar e ir al estado 79
    PRUEBA         desplazar e ir al estado 80
    REPETIR        desplazar e ir al estado 81
    SALIR          desplazar e ir al estado 82
    SI             desplazar e ir al estado 83
    SIGUIENTE      desplazar e ir al estado 84
    IDENTIFICADOR  desplazar e ir al estado 85
    ';'            desplazar e ir al estado 86

    error          [reduce usando la regla 114 (instruccion)]
    CASOS          [reduce usando la regla 114 (instruccion)]
    CUANDO         reduce usando la regla 114 (instruccion)
    DEVOLVER       [reduce usando la regla 114 (instruccion)]
    EXCEPCION      reduce usando la regla 114 (instruccion)
    FIN            reduce usando la regla 114 (instruccion)
    FINALMENTE     reduce usando la regla 114 (instruccion)
    LANZA          [reduce usando la regla 114 (instruccion)]
    MIENTRAS       [reduce usando la regla 114 (instruccion)]
    PARA           [reduce usando la regla 114 (instruccion)]
    PRUEBA         [reduce usando la regla 114 (instruccion)]
    REPETIR        [reduce usando la regla 114 (instruccion)]
    SALIR          [reduce usando la regla 114 (instruccion)]
    SI             [reduce usando la regla 114 (instruccion)]
    SIGUIENTE      [reduce usando la regla 114 (instruccion)]
    SINO           reduce usando la regla 114 (instruccion)
    IDENTIFICADOR  [reduce usando la regla 114 (instruccion)]
    ';'            [reduce usando la regla 114 (instruccion)]

    nombre                             ir al estado 87
    instruccion                        ir al estado 169
    instruccion_asignacion             ir al estado 89
    instruccion_devolver               ir al estado 90
    instruccion_llamada                ir al estado 91
    llamada_subprograma                ir al estado 92
    instruccion_si                     ir al estado 93
    instruccion_casos                  ir al estado 94
    instruccion_bucle                  ir al estado 95
    clausula_iteracion                 ir al estado 96
    instruccion_interrupcion           ir al estado 97
    instruccion_lanzamiento_excepcion  ir al estado 98
    instruccion_captura_excepcion      ir al estado 99
    objeto                             ir al estado 100

(对不起,如果翻译不是100%准确)

我猜想它与递归规则有关,但是我不知道如何解决它,因为我需要规则“ instruccion”来解析多个指令。因此,如果有人知道如何解决冲突,那就太好了。

谢谢!

0 个答案:

没有答案
相关问题