[antlr-interest] Resuming While loop

Jim O'Connor Jim.OConnor at microfocus.com
Thu Apr 10 06:04:17 PDT 2003


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 yahoo.com]
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