[antlr-interest] Parsing a file

Jim Idle jimi at temporal-wave.com
Wed Nov 12 11:52:56 PST 2008


On Thu, 2008-11-13 at 03:59 +0900, Yuri Tijerino wrote:
> Thank you Sam,
> 
> This sounds like what I am looking for.  However, I am having hard-time 
> understanding how those functions work.  I have looked at the API, but 
> would appreciate an example of how to modify those.  Let me know if you 
> come across any examples.

You could download thew source code for the Open JavaFX compiler. IN
there I use two techniques for error recovery so that for instance
parsing members of class definitions does not cause an exit of the
entire class parsing rules, but just consumes tokens until it finds a
member of first() of a class member declaration.

This probably does everything you want and is properly documented with
comments.

Jim

> 
> Yuri
> 
> Sam Harwell wrote:
> > You can also implement your own recovery mechanism by overriding
> > recover, recoverFromMismatchedSet, recoverFromMismatchedToken and/or the
> > functions the base versions call. For a C/C++-style language, I suppose
> > one might try to recover by skipping to a } or a ;. I haven't
> > implemented the best error handling in my primary grammar yet; after I
> > have I'll probably have more information about the results.
> >
> > Sam
> >
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org
> > [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gavin Lambert
> > Sent: Wednesday, November 12, 2008 12:19 PM
> > To: Yuri Tijerino; antlr-interest at antlr.org
> > Subject: Re: [antlr-interest] Parsing a file
> >
> > At 06:49 13/11/2008, Yuri Tijerino wrote:
> >  >> What I really want is change the default behavior and throw
> >  >> away the tokens that cause the exception and continue
> >  >> parsing the input after those tokens as if it was a new
> >  >> input.  Is this even possible?
> > [...]
> >  >Isn't this in a way what the Lexer does when trying to find
> >  >tokens based on EBNF rules?  How do I duplicate that behavior
> >  >in the parser rules so that it won't stop trying to match the
> >  >rest of the input when a rule partially matches something and
> >  >it can't recover automagically?
> >
> > You could try turning backtracking on, and have as your final alt 
> > something that consumes a single token and then tries the standard 
> > recognition again.  Something like this:
> >
> > start
> >    :  ( somethingvalid |  somethingelse | . )* EOF
> >    ;
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-addr
> > ess
> >
> >
> >   
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 



More information about the antlr-interest mailing list