Stefan Kuhn wrote:
> Hello again,
>
> I`m developing a parser using ANTLR 2.7.4 generating java code with no
> AST. After parsing, I need to check (in some other class) if an error
> occurred during parsing. Is there any "error counter" or "error occured"
> variable in the Parser I can access from another package?
>
> -stefan
Hi, Stefan!
I had the same problem, but a look at http://www.antlr.org/doc/err.html
helped me a lot.
In my parser I have a (main) rule like this. I added the exception block
after it and now I'm able to handle the errors myself-
[..]
do***ent
: DOCTYPE TITLE ROOT OFOLDER
((ODT(folder|bookmark))|SEPARATOR)* CFOLDER
;
exception
catch [RecognitionException ex] {
// re****tError(ex.toString());
throw ex;
}
[..]
Now, when I'm invoking my parser I'm able to catch the exceptions ...
[..]
try {
parser.do***ent();
} catch (RecognitionException e) {
e.printStackTrace();
return null;
} catch (TokenStreamException e) {
e.printStackTrace();
return null;
}
[..]
Regards,
Christian
--
Christian Junk <junkc@[EMAIL PROTECTED]
>
University of Applied Sciences, Trier


|