[antlr-interest] Exceptional question...:)

Robert Hill rob.hill at blueyonder.co.uk
Sat Jul 2 14:25:57 PDT 2005


I have a rule which has a syntactic predicate which allows or disallows junk
chars on the end of a line after all my expected tokens. If this is turned
off, and im just expecting a carriage return, I want to throw an exception
and notify the user that there's junk on the end of a line, so I added an
exception on this alternate.

 

So far the rule looks like this

 

Element

Options { defaultErrorHandler = false; }

:

      ty:type nn:ID (ID! | HYPHEN!) cnt:element_count (INT | HYPHEN)
string_size[#ty.getText()] 

            (INT | HYPHEN)  ({bIgnoreExtraneousEOLChars}? (options
{greedy=false;}:~CR!)* CR! 

| CR! exception

catch [RecognitionException] {

                  throw new ArgumentException(ErrorPrefixLine(nn) + "ERROR :
extraneous character before newline");

}  )

    {

            #element = #([TOK_TYPE,"TOK_TYPE"], #element);

    } //Add a new root element

      ;

exception

catch [RecognitionException] {

                  throw new ArgumentException(ErrorPrefixLine(nn) + "ERROR :
Syntax error found processing element");

}

 

But the exception for the CR alternate never gets thrown, only the rule's
exception gets thrown. Ie, if the Var

bIgnoreExtraneousEOLChars is false, and the CR! Alternater production
doesn't match , I want the exception to throw I've tried allsorts, and
checked some of the other grammars on the site but cant see anything similar
as a starting point. any takers?

 

 

Also whilst I'm asking daft questions ;) 

I've seen these 3 different variations on inserting the tokens into an AST,
and after trying them out , and examining the code it appears they generate
the same instructions.

 

                  ## = #([TOK_COMMENT,t]);

                  #comment = #([TOK_COMMENT,t]);

                  #comment = #(#[TOK_COMMENT,t]);

 

So, if they all generate the same code, why the multiple syntax?

Throwback to pccts perhaps? 

 

Cheers,

/2ob

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050702/09df1be2/attachment.html


More information about the antlr-interest mailing list