[antlr-interest] I want to throw an exception and stop parse, please!

Indhu Bharathi indhu.b at s7software.com
Mon May 25 00:20:21 PDT 2009


Ah, forgot. Things changed after the book was written. I guess you have to override the following two methods from BaseRecognizer

void  recover (IntStream input, RecognitionException re)
Object  recoverFromMismatchedSet (IntStream input, RecognitionException e, BitSet follow) throws RecognitionException

Cheers, Indhu

  ----- Original Message ----- 
  From: Kevin Chen 
  To: indhu.b at s7software.com 
  Cc: antlr-interest at antlr.org 
  Sent: Monday, May 25, 2009 11:48 AM
  Subject: RE: [antlr-interest] I want to throw an exception and stop parse,please!


  Thanks for your reply!

  I cannot find "mismatch" method in "org.antlr.runtime.Parser" and "org.antlr.runtime.BaseRecognizer" both, just found "recoverFromMismatchedSet" method in "org.antlr.runtime.BaseRecognizer".      :-)

  My antlr runtime version is 3.1.3.

  Thanks a lot!     :-)

------------------------------------------------------------------------------

    >Two methods of parser (mismatch and recoverFromMismatchedSet) are responsible for auto-recovery and showing >error messages.
    > 

    >If you want to throw an exception and exit right on the first error you need to override these methods and >just throw the exception instead of handling it.
    > 

    >Something like this:
    > 

    >@members {

    >protected void mismatch(IntStream input, int ttype, BitSet follow)
    >throws RecognitionException
    >{
    >throw new MismatchedTokenException(ttype, input);
    >}
    >
    >public void recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow)
    >
    >throws RecognitionException
    >
    >{
    >
    >throw e;
    >
    >}
    > 
    >}
    > 

    >Cheers, Indhu


------------------------------------------------------------------------------
  Windows Live™: Keep your life in sync. Check it out! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090525/aaf5e1bd/attachment.html 


More information about the antlr-interest mailing list