Re: Empty token sequence



Cesare Zecca wrote:

Warning: Line 153, Column 9: This choice can expand to the empty
token sequence and will therefore always be taken in favor of the
choices appearing later.


javacc complains that within Factro() non terminal the Id() might be
choosen to the detriment of the following choice (GroupId())

In this case the problem is in Factor: all the calls are erroneously
inside java code sections, so to JavaCC it looks like Factor calls no
productions or tokens.

----------

String
Factor() :
{
Token lToken;
String lResult;
}

{
{
lResult = Id(); // bug: inside {javacode}
return lResult;
}
| {
lResult = GroupId(); // bug: inside {javacode}
return lResult;
}

} // end Gpl.Factor()

----------

String
Factor() :
{
Token lToken;
String lResult;
}

{
lResult = Id() // fix: outside {javacode}
{ return lResult; }
|
lResult = GroupId() // fix: outside {javacode}
{ return lResult; }

} // end Gpl.Factor()

----------

Hope this helps!

.



Relevant Pages

  • Unary minus
    ... I tried to add the unary minus to my Gpl.jj grammar (derived from ... String lResult; ... Unit tests for JavaCC tokens ...
    (comp.compilers.tools.javacc)
  • Emtpy token sequence
    ... about the "empty token sequence" issue. ... JavaCC tokens and productions ... String lResult; ...
    (comp.compilers.tools.javacc)
  • Re: Unary minus
    ... productions, not two separate tokens. ... lTermImages.addElement(lResult); ...
    (comp.compilers.tools.javacc)
  • Actual vs symbolic token image
    ... PAR_OPEN and PAR_CLOSED have been made tokens too: ... String lResult; ... The String result printed out for explanation purposes for the "((a + ... } // end class Gpl ...
    (comp.compilers.tools.javacc)