BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Java line numbering option produces undeclared variables causing build to fail #246

Closed knopt closed 5 years ago

knopt commented 5 years ago

Hi there,

I'm using BNFC for Java with line numbering (bnfc -l -java15). My parser.java file comprise undeclared variables causing a build to fail. The variables are supposed to be responsible for line numbering.

Sample code from my parser.java

        int p_1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
        int p_1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
        Latte.Absyn.Expr p_1 = (Latte.Absyn.Expr)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
        int p_2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left;
        int p_2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right;
        Object p_2 = (Object)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
        int p_3left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
        int p_3right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
        Latte.Absyn.Expr p_3 = (Latte.Absyn.Expr)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
         RESULT = new Latte.Absyn.EOr(p_1,p_3);
java_cup.runtime.ComplexSymbolFactory.Location leftLoc = getLeftLocation(p_1xleft,p_3xleft);
if (leftLoc != null) {
  ((Latte.Absyn.EOr)RESULT).line_num = leftLoc.getLine();
  ((Latte.Absyn.EOr)RESULT).col_num = leftLoc.getColumn();
  ((Latte.Absyn.EOr)RESULT).offset = leftLoc.getOffset();
} else {
  ((Latte.Absyn.EOr)RESULT).line_num = -1;
  ((Latte.Absyn.EOr)RESULT).col_num = -1;
  ((Latte.Absyn.EOr)RESULT).offset = -1;
} 

As you may notice, p_1xleft and p_3xleft are not declared nor assigned with any values. The are produced by: CFtoCup15.hs, however I can't see any place in the code where they actually are supposed to be declared/assigned values with. Variables p_1left, p_1right etc are unused.

Could you please help me solve this problem? If you'd like me to provide my grammar or anything more, please let me know.

Thanks

andreasabel commented 5 years ago

This issue has been closed. How was it resolved?