[antlr-interest] Testing ANTLR grammar as a whole.

Bharath S bharath at starthis.com
Wed May 5 08:18:51 PDT 2004


Hi Antlers,

If I wanted to test the antlr grammar as a whole instead of testing
individual rules, should I rewrite my rules such that the first rule that I
call is the combination of all other rules? For example, if I have a pascal
grammar and I feed the input as a test.pas file, I want the parser to test
the entire *.pas file for syntax instead of providing command line input to
test each rule individually.

I saw the pascal grammar at antlr.org and it has one single rule called
"program heading" which seems to be highest rule in the hierarchy. To follow
the same approach, I have to rewrite my rules. Is there any other option by
which I can test my entire program instead of just individual rules, without
rewriting the existing grammar?

I am also following the discussion that Mark (Wheatfarm) has had with the
'Compiler design workflow' thread. Any comments on this regard will be
greatly appreciated.

Thanks!

Bharath. 

-----Original Message-----
From: Anakreon [mailto:anakreonmejdi at yahoo.gr] 
Sent: Wednesday, April 28, 2004 4:48 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] ANTLR grammar: Clarifications needed

Bharath S wrote:
> Hi Antlers,
> 
> I have a rule of the form: 
> **
> Statements: (statement)* ;
> **
> and I get a warning "Non-determinism between Alt 1 and exit branch of
> block". If I use the "warnWhenFollowAmbig = false" command, I still get
the
> error. Any ideas?
> 
> Also, I am wondering how to differenciate between two rules, BOOLEAN and
> INTEGER in the lexer. They are of the form:
> 
> BOOLEAN: '1'|'0';
> INTEGER: ('0'..'9')+(UNDERSCORE ('0'..'9')+ )?;
> 
> Can I differenciate these rules without making them "protected"?
> 
> Thanks!!
> 
> Bharath.

I would declare only rule NUMBER in the lexer.
Then I would have a rule lat's call it bool_rule
bool_rule
   :
   n:NUMBER {
    int val = Integer.parseInt(#n.getText());
    if (val < 0 || val > 1) {
       throw new ANTLRException(...);
    }
    #n.setType(BOOLEAN);
   }
   ;
Then whenever a boolean is expected I'd call the bool_rule.
Perhaps a decendant of ANTLRException should be thrown.


 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list