[antlr-interest] count number of times a rule is called

Harmon Nine hnine at isis.vanderbilt.edu
Thu Nov 15 12:06:59 PST 2007


Atif --

 

(Someone pls. correct if wrong)

 

At the top of the parser ".g" file, define a public property for your
parser class:

 

@members {

  public int rule_exec_count = 0;

}

 

Then, in the rule in question, increment this property using an embedded
action:

 

myrule   :  { rule_exec_count++; } <rule body> ;

 

When the parsing is done, you can access the public member
"rule_exec_count" using the "parser" object in your driver:

 

MyParser parser = new MyParser( lexer );

parser.start_rule();

...

System.out.println( "myrule was called " + parser.rule_exec_count + "
times." );

 

HTH

-- Harmon

 

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of atif azad
Sent: Thursday, November 15, 2007 12:13 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] count number of times a rule is called

 

Dear all

 

I want to count the number fo times a rule is called for a certain input
file.

Does any body has an idea how to do it in the simplest way.

 

regards

Azad , Atif

 




________________________________

Express yourself instantly with MSN Messenger! MSN Messenger
<http://g.msn.com/8HMAEN/2737??PS=47575>  Download today it's FREE!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071115/1eddbc54/attachment.html 


More information about the antlr-interest mailing list