[antlr-interest] Re: Real examples of error recovery

Paul J. Lucas dude at darkfigure.org
Tue Aug 24 09:00:59 PDT 2004


--- In antlr-interest at yahoogroups.com, Richard Clark <rd_clark at s...> wrote:
> Paul, can you provide some examples of where you think the lexer would 
> need to backtrack?

I never said it needed to backtrack.  I said it needed to change state.  Look at:

http://www.w3.org/TR/xquery/#id-lexical-states

(I'm making this example up as I go, but hopefully, you get the idea.)  Suppose you start in 
the default state.  Now you get:

declare collation "foo";

The "keyword" of "default" is missing.  Hence the lexer never switches to the 
NAMESPACEDECL state.  Before I lex "foo" I need to poke the lexer and be able to forceably 
switch its state to NAMESPACEDECL.  Or make the lexer skip forward to just past the ';' and 
reset its state.  Or something.

FYI: because all of the complexity is in the lexer, it makes writing the grammar for the 
parser be as if XQuery *does* have keywords, i.e., you write the grammar "normally," e.g.:

defaultCollationDecl : DECLARE DEFAULT COLLATION uri=stringLiteral ;

How would I annotate the above grammar rule with an "exception/catch" and make a best 
effort to continue?  How to tell the lexer to do something like "skip until you find a ';'"?  
>>From the ANTLR docs, putting an "exception/catch" on the entire rule implies rule 
termination unlike "exception/catch" on either a labeled statement or an alternate.

- Paul



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list