I have a problem on my parser generator (with javaCC)
I have this error :
Warning: Choice conflict involving two expansions at
line 119, column 3 and line 119, column 43 respectively.
A common prefix is: <CONSTANT>
Consider using a lookahead of 2 for earlier expansion.
Warning: Choice conflict involving two expansions at
line 119, column 3 and line 119, column 43 respectively.
A common prefix is: <CONSTANT>
Consider using a lookahead of 2 for earlier expansion.
because of this part of my code :
TOKEN : /* OPERATORS */
{
< POINT : "." >
| < VIRGULE : "," >
}
TOKEN :
{
< CONSTANT : (< DIGIT >)+ >
| < STRING : ( ["A"-"Z","a"-"z"] )+ >
| < #DIGIT : [ "0"-"9" ] >
}
void number() :
{
}
{
(< CONSTANT > < POINT > < CONSTANT >) | (< CONSTANT >)
}
Maybe it's because i have 2 CONSTANT on both side of my expression "|"
I have seen that i can use LOOKAHEAD But don't understant what is his utility
Thanks for your help because i don't understant :(
Top-down parsers, such as the ones JavaCC builds, need to know in advance which choice to take, based on the next token, or next few tokens. The tokens examined to make this decision are the "lookahead tokens".
Ideally, the decision can be made with the immediately following token; if not, the parser needs to buffer following tokens and it also needs to have a much larger decision table. There is no algorithm which can predict how many lookahead tokens are necessary, so JavaCC requires you to tell it. That's what those error messages are asking you to do.
If two applicable choices start with the same token, then that token can't help the parser decide which choice to take, so it needs to look at least one more token ahead. Clearly, anything other than a POINT
following the initial digits indicates that the NUMBER
must match the second choice. Assuming that a number
cannot be followed by a POINT
, then a POINT
following the initial digits indicates that NUMBER
. In that case, a lookahead of 2 is sufficient. If, however, a number
can be followed by a POINT
, then the parser will have to look further ahead to decide.