Loading ...
Sorry, an error occurred while loading the content.

Throw an exception with my own message

Expand Messages
  • Anna Winkler
    Hi, How do I throw an exception for a rule with my own message? I have defaultErrorHandler = false in my parser. The rule I have is: declarator { int limit_3
    Message 1 of 2 , Aug 31, 2000
    • 0 Attachment
      Hi,

      How do I throw an exception for a rule with my own message? I have
      defaultErrorHandler = false in my parser.

      The rule I have is:

      declarator
      {
      int limit_3 = 1;
      } :
      ({ limit_3 <= 3 }? limit_3 = dimension[limit_3] )+ SEMI!
      {
      if (limit_3 > 3)
      {
      throw antlr::RecognitionException ("My error message");
      }
      }
      ;

      dimension[int i] returns [int limit]:
      LEFT_BRACKET! logical_or_expr RIGHT_BRACKET!
      { limit = i + 1; }
      ;

      But the exception isn't thrown.

      Thanks,
      Anna
    • Terence Parr
      ... Then that java code is not being executed. Ter -- Chief Scientist & Co-founder, http://www.jguru.com Co-founder, http://www.NoWebPatents.org -- Stop Patent
      Message 2 of 2 , Sep 4, 2000
      • 0 Attachment
        Thursday, August 31, 2000, Anna Winkler hath spoken:

        > How do I throw an exception for a rule with my own message? I have
        > defaultErrorHandler = false in my parser.

        > The rule I have is:

        > declarator
        > {
        > int limit_3 = 1;
        > } :
        > ({ limit_3 <= 3 }? limit_3 = dimension[limit_3] )+ SEMI!
        > {
        > if (limit_3 > 3)
        > {
        > throw antlr::RecognitionException ("My error message");
        > }
        > }
        > ;

        > dimension[int i] returns [int limit]:
        > LEFT_BRACKET! logical_or_expr RIGHT_BRACKET!
        > { limit = i + 1; }
        > ;

        > But the exception isn't thrown.

        Then that java code is not being executed.

        Ter



        --
        Chief Scientist & Co-founder, http://www.jguru.com
        Co-founder, http://www.NoWebPatents.org -- Stop Patent Stupidity
        parrt@...
      Your message has been successfully submitted and would be delivered to recipients shortly.