[antlr-interest] way to rewind the token stream

Tarun Khanna tarunkhanna at gmail.com
Thu Jul 28 12:47:30 PDT 2005


Consider this rule
Class MyParser extends parser;
{
boolean d;
MyParser(Lexer lexer)
{
this(lexer);
d = false;
}
}

A: B

B: C | (D {d = true;})

Now what I want to do is to check if the token D appears in the rule. If it 
does appear, then I want to replace it with C and then resume parsing from 
the beginning of rule A again.

Please advice if it is possible to do and how if it is?

Thanks 
Tarun

On 7/28/05, Prashant Deva <prashant.deva at gmail.com> wrote:
> 
> The rewind method is used for syntactic predicates inside the
> generated parser/lexer/treeparser.
> 
> PRASHANT
> 
> On 7/28/05, Tarun Khanna <tarunkhanna at gmail.com> wrote:
> > I noticed a rewind method in the Parer Class. Can it be used to rewind 
> the
> > token stream to a previous location for resync purposes? Will it also 
> rewind
> > the character sream for the lexer. I am trying to find a way to resync 
> the
> > parser to a previous location after an error occurs.
> >
> > --
> > Tarun Khanna
> 



-- 
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050728/6e39f700/attachment.html


More information about the antlr-interest mailing list