Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools Pccts > Re: ANTLR: Dete...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 76 of 135
Post > Topic >>

Re: ANTLR: Determine if an error occured

by Christian Junk <junkc@[EMAIL PROTECTED] > Nov 19, 2004 at 06:44 PM

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
 




 3 Posts in Topic:
ANTLR: Determine if an error occured
Stefan Kuhn <Stefan.Ku  2004-11-18 18:13:40 
Re: ANTLR: Determine if an error occured
Christian Junk <junkc@  2004-11-19 18:44:46 
Re: ANTLR: Determine if an error occured
Stefan Kuhn <Stefan.Ku  2004-11-29 14:43:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 8:27:17 CST 2008.