Hello,
I do not understand how lookahead works exactly.
In a regex, I can use a expression like this: "A+A", which means to get as many As and finally get another A.
(I know that it is equivalent to "AA+" which is simplier, but the previous is an example to help me understand lookahead in javacc)
I've tried to reproduce the "A+A" example in javacc, but it does not work.
From my understanding, a LOOKAHEAD of 2 could process the input "AAA", and a LOOKAHEAD of 4 could process the input "AAAA".
Why this example is not working?
++++++++++++++++++++++++++++++++++
options { STATIC = false; }
PARSER_BEGIN(B)
import java.io.*;
public class B {
static String test = "AAA";
public static void main(String args[]) throws Exception {
B app = new B();
BTokenManager ttm = new BTokenManager(new SimpleCharStream(new StringReader(test)));
app.ReInit(ttm);
app.Entry();
}
public B() { this((Reader) null); }
}
PARSER_END(B)
TOKEN : { <A: "A"> }
void Entry() : { }
{
( LOOKAHEAD(2) <A> )+
<A>
}
++++++++++++++++++++++++++++++++++
Best regards,
DAvid