How can I properly recover from lexical errors in parser.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vadim_Solonovich
Posted On:   Wednesday, February 20, 2002 11:07 AM

I would like to recover from lexical errors in parser (i.e. NoViableAltForCharException ) by skipping input until some set of tokens I know about. My Lexer has defaultErrorHandler=false option set so passing all recognition errors to parser as TokenStreamException . I use the following code in Parser : rule: : ... ; exception catch [TokenStreamException e] { boolean consuming = true; while ( consuming ) { consume(); switch(LA(1)) { case TOKEN_1: case TOKEN_2: ... case EOF: consuming = false; break; } } } The    More>>

I would like to recover from lexical errors in parser (i.e. NoViableAltForCharException ) by skipping input until some set of tokens I know about. My Lexer has defaultErrorHandler=false
option set so passing all recognition errors to parser as TokenStreamException .

I use the following code in Parser :



			

rule:
: ...
;

exception
catch [TokenStreamException e] {
boolean consuming = true;
while ( consuming ) {
consume();
switch(LA(1)) {
case TOKEN_1:
case TOKEN_2:
...
case EOF:
consuming = false;
break;
}
}
}





The problem is that consume() does not consume an invalid token and advance input as I expect causing the parser to receive the same TokenStreamException on call to LA(1) .

How can I properly handle this situation ?



Thanks in advance.    <<Less
About | Sitemap | Contact