Yeas that's because the default lookahead is 1On May 31, 2019 2:51 AM, Hongze Zhang <notifi...@github.com> wrote:
Thanks @new-javacc .
Just to reiterate LOOKAHEAD(2) says upto two tokens but if the choices are less than 2 tokens long, it will not use 2.
Sorry I don't think so (If I understand your point correctly). For example, I can write following grammars:
( LOOKAHEAD(2) ( <FOO> | <BAR> ) <DUMMY> | <BAR> <BAR> )
( ( <FOO> | <BAR> ) <DUMMY> | <BAR> <BAR> )
By your explanation, the 2 grammars should be effectively equivalent, because the leading expansion ( <FOO> | <BAR> ) is a choice with no longer than 2 tokens. However, grammar 1 can parse
BAR BARcorrectly, where grammar 2 cannot. I think the behavior is right.
Per lookahead tutorial and JavaCC generated code, I believe a lookahead hint in choice should be the lookahead for the whole choice branch, not only the first expansion. Say, the lookahead in
LOOKAHEAD(2) ( <FOO> | <BAR> ) <DUMMY> | ...should consider
( <FOO> | <BAR> ) <DUMMY>, not only the sub choice
( <FOO> | <BAR> ), so I don't think length of the sub choice matters.
You are receiving this because you were mentioned.
Just in case anyone else is wondering what this is about. It's issue 86 on the GitHub.
I mention this, because it took me a long time to figure out what this discussion is about. I'd suggest that further discussion should be on GitHub because that's where it started, because that's where the context is, and because it's best to have discussions like this in one place.
But thanks for bringing this to our attention.