[antlr-interest] How to put back a token read by lexer
Sinan
sinan.karasu at boeing.com
Thu Oct 25 15:06:38 PDT 2001
cela_vei at yahoo.com wrote:
>
> I want to put back the most recently read token back into the
> input stream. I searched through the archive and found that people
> have asked this question multiple times but without an answer.
>
> Please Help
> Cela Vei
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Do something like the following to implement your own push....
public class MyTokenStreamSelector extends TokenStreamSelector {
public MyTokenStreamSelector() {
super();
...create some kind of stack.....
}
public void pushToken(Token token) {
....push it somewhere;
}
public Token nextToken() throws TokenStreamException {
if anything pushed, pop an return it
else
try {
Token tok = super.nextToken();
return tok;
}
catch (TokenStreamRetryException r) {
// whatever.....
}
}
}
}
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list