[antlr-interest] Re: exception thrown in syntatic predicate c an't be caught!

mzukowski at yci.com mzukowski at yci.com
Mon Apr 14 15:15:09 PDT 2003


Why do you have garbage characters in statements?

You could handle this in your lexer too, by consuming characters until you
see a SEMICOLON, but you also have to handle comments and strings properly.
Then when you throw that exception, the next thing the parser sees should
always be a SEMICOLON.

Monty

-----Original Message-----
From: martinkbraid [mailto:mbraid at sqlworks.com]
Sent: Monday, April 14, 2003 3:08 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: exception thrown in syntatic predicate
can't be caught!


The input to my lexer/parser is a series of statements delimited by 
semicolons. I was using the lexer exception to tell the parser to 
skip over the current statement and consumeUntil() the next semicolon 
(ie skip over the remainder of the stmt). Since I posted my message I 
made some progress by using the filter=rule option in the lexer and 
have that rule automatically throw a TokenStreamException which my 
parser captures. That works ... to a point. When the parser gets that 
exception it does a consumeUntil(SEMICOLON), but if there is a 2nd 
garabage character the lexer throws another exception and the whole 
thing becomes a mess.

Think I'll heed your advice and look at controlling the lexer more 
carefully.


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Syntactic predicates work by trying a piece of syntax and then 
checking if
> an exception was thrown.  When it finds a predicate that works it 
then calls
> the parser for real, with actions turned back on.  Syntactic 
predicates
> won't work if you can catch their exceptions.  Catch the exception 
after the
> predicate has decide where to go.
> 
> Or just catch and handle the exception in the lexer.  What exactly 
are you
> doing with the exceptions anyhow?
> 
> Monty
> 
> -----Original Message-----
> From: martinkbraid [mailto:mbraid at s...]
> Sent: Sunday, April 13, 2003 7:07 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] exception thrown in syntatic predicate 
can't
> be caught!
> 
> 
> Because I need to be able to handle garbage characters passed to my 
> parser/lexer, I'm doing my own error processing in a top level rule 
> by catching ANTLRExceptions. 
> 
> By chance, during syntactic predicate processing, the lexer 
> encounters a garbage character and throws a TokenStreamException. 
But 
> because inputState.guessing > 0 (because it was in a syntactic 
> predicate), my exception handler does NOT get control and the 
> exception passes out of the parser. What do I do? It would be 
> impossible to avoid syntatic predicates?
> 
> Thanks, Martin Braid
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

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


 

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




More information about the antlr-interest mailing list