CFG of declaration of variables and functions with reduce-reduce conflict

41 Views Asked by At

I was working on a compiler for certain language similar to C++ with the tools flex and bison. I'm new to them and I found it difficult dealing with the reduce-reduce conflict between variable declarations and function definitions.

here is an example given by bison.

reduce/reduce conflict on token Ident [-Wcounterexamples]
time limit exceeded: 6.000000
  First example: Int • Ident ArraySizeList '=' InitVal ';' $end
  First reduce derivation
    $accept
    ↳ 0: CompUnits                                                                             $end
         ↳ 2: CompUnit
              ↳ 3: Decl
                   ↳ 6: VarDecl
                        ↳ 22: BType      VarDefList                                        ';'
                              ↳ 8: Int • ↳ 24: VarDef
                                               ↳ 25: Element                   '=' InitVal
                                                     ↳ 14: Ident ArraySizeList
  Second example: Int • Ident '(' FuncFParams ')' Block $end
  Second reduce derivation
    $accept
    ↳ 0: CompUnits                                                   $end
         ↳ 2: CompUnit
              ↳ 4: FuncDef
                   ↳ 31: FuncType    Ident '(' FuncFParams ')' Block
                         ↳ 33: Int •

I tried to look for some commands to specify the precedence in vain. maybe it's nothing about the precedence, I guess. how could I solve the problem? thanks in advance.

0

There are 0 best solutions below