[antlr-interest] Re: Resuming While loop

madison_stjames madison_stjames at yahoo.com
Thu Apr 10 09:36:55 PDT 2003


Thanks Jim!

I just re-read my question and realized just what a newbie I was. 
(It can be a little intimidating out here sometimes, given the 
expertise of a lot of the folks on this board.)

I found some similar information in the documentation. I took your 
approach, with the exception of using consume(). This may be exactly 
what I am looking for.

I've got some more trial and testing to do. If I have any 
breakthroughs... I'll be sure to share.

Thanks Again!

--- In antlr-interest at yahoogroups.com, "Jim O'Connor" 
<Jim.OConnor at m...> wrote:
> Hello,
>   I'm interested in the topic, as well.  The Error Handling and 
Recovering
> in the documentation contains a good start.
> http://www.antlr.org/doc/err.html#_bb3.  The implementation below 
is
> described in the second to last bolded section on the page
> "Specifying Parser Exception-Handlers".
> 
> 
>   I have a start at the mechanism you talk about.  You talk 
about "looping"
> and making modifications in the "main" method.  The error recovery 
is
> specified in the parser.  If that is not what you are looking for, 
please
> clarify.
> 
>   The mechanism below may not be the "recommended" way of 
proceeding.  An
> experienced Error recovery person could comment :0).
>   I catch the exception in the parser and "consume until" the 
parser can
> recognize a starting point.  
> 
> 
> //just to get the general idea
> startRule
>   : (statement)+
>   ;
> 
> statement: DSLASH operation parameters;
> 
> parameters
>  : parameter (COMMA parameter)*;
> 
> parameter
>   : THIS
>   | THAT
>   | THE
>   | OTHER
>   ;
>     exception
>     catch [RecognitionException ex] {
>        reportError("Here I am parameter : " +  ex.toString());  
>        consume(); //eat the offending token
>        consumeUntil(DSLASH);  //eat the tokens until I can start a 
rule
>      }
> 
> Any suggestions are welcome.
> 
> Jim
> 
> 
> 
> 
> -----Original Message-----
> From: madison_stjames [mailto:madison_stjames at y...]
> Sent: Wednesday, April 09, 2003 11:21 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Resuming While loop
> 
> 
> My parser currently stops processing at the point at which it 
> encounters an error in the file being processed. It writes out the 
> error to the screen, then quits. A quick look at the code reveals 
> why this is happening:
> 
> class myParser
> {
> 	public static void Main(string[] args) 
> 	{
> 		try 
> 		{
> 			T lexer = new T(new CharBuffer(Console.In));
> 			P parser = new P(lexer);
> 			parser.startRule();
> 			bool done = false;
> 			while ( !done ) 
> 			{
> 				Token tok = lexer.nextToken();
> 				Console.Out.WriteLine("Token: "+tok);
> 				if ( tok.Type==Token.EOF_TYPE ) {
> 					done = true;
> 				}
> 			}
> 			Console.Out.WriteLine("done lexing...");
> 		} 
> 		catch(Exception e) 
> 		{
> 			Console.Error.WriteLine("exception: "+e);
> 
> 		}
> 
> 	}
> }
> 
> What I want to do is modify the main method so that, upon 
> encountering an error, the parser will write it out, then continue 
> processing the rest of the file.
> 
> I have tried several different approaches, all of which have 
failed.
> 
> Suggestions....?
> 
> Thanks in Advance!
> 
> 
>  
> 
> 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