The parser generated from the following grammar fails, unless I activate the commented-out superfluous rule:
parser grammar RightRecParser;
options { tokenVocab = RightRecLexer; }
listInteger returns [ int result ]
: /* empty */
{ $result = 0; }
| n=INTEGER m=listInteger
{ $result = Integer.parseInt($n.getText()) + $m.result; }
;
// // The following irrelevant rule makes the parser succeed:
// foo returns [ int result ]
// : m=listInteger
// { $result = $m.result; }
// ;
Behavior without foo:
echo "1 2" | java -cp .:/Users/abel/bnfc/testing/data/antlr-4.7.2-complete.jar RightRec.Test
line 1:0 no viable alternative at input '1'
Behavior with foo:
echo "1 2" | java -cp .:/Users/abel/bnfc/testing/data/antlr-4.7.2-complete.jar RightRec.Test
3
I would expect that an unused rule is not needed to generate a working parser. These grammars are originally auto-generated by the BNFC tool, --antlr backend. Adding redundant rules by hand is thus not a viable workaround.
Lexer is unsurprisingly:
lexer grammar RightRecLexer;
// Whitespace
WS : (' ' | '\r' | '\t' | '\n' | '\f')+ -> skip;
// Numbers
fragment DIGIT : [0-9] ;
INTEGER : DIGIT+;
The full MWE is attached (including Makefile and Test wrapper).
bug.zip
The parser generated from the following grammar fails, unless I activate the commented-out superfluous rule:
Behavior without
foo:Behavior with
foo:I would expect that an unused rule is not needed to generate a working parser. These grammars are originally auto-generated by the BNFC tool,
--antlrbackend. Adding redundant rules by hand is thus not a viable workaround.Lexer is unsurprisingly:
The full MWE is attached (including Makefile and Test wrapper).
bug.zip