BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
578 stars 163 forks source link

Java: jflex-generated lexer with line numbers fails to build #453

Closed andreasabel closed 11 months ago

andreasabel commented 11 months ago

Concerns option combination --java --jflex -l:

javac -sourcepath . test/Yylex.java test/parser.java test/sym.java
test/Yylex.java:296: error: no suitable constructor found for Location(int,int,long)
    return new ComplexSymbolFactory.Location(yyline+1, yycolumn+1, yychar);
           ^
    constructor Location.Location(int,int,int) is not applicable
      (argument mismatch; possible lossy conversion from long to int)

This could be due to an incompatibility with JFLex 1.8.

andreasabel commented 11 months ago

Indeed, since JFLex 1.8 yychar is a long rather than an int to allow inputs > 2GB. It seems that JavaCUP has not provided a ComplexSymbolFactoryLocation(int, int, long) constructor yet.

Our workaround is to cast yychar to int when creating a Location. This will produce garbage for inputs > 2GB due to overflow, but this is the situation with JFLex < 1.8 anyway. A proper fix has to wait for JavaCUP to catch up.