[antlr-interest] TokenStreamRewriteEngine + java profiling

Edward O'Flynn esof1 at student.cs.ucc.ie
Tue Jan 10 03:51:12 PST 2006


Hi all

I am using the TokenStreamRewriteEngine to build a java profiling tool, 
that will
count primitive operations, e.g. assignment opertations, comparative 
ops, aritmetic ops.
The way I want to rewrite the code is as follows
e.g.

for(int i=0+counter.incAssign();i<3+counter.incCompar() && 
i>-1+counter.incCompar(), i++)
{//code
}

where counter.incCompar() returns 0

The way i am writing this is as follows

forCond
    :    (expression)?
        {#forCond = #(#[FOR_CONDITION,"FOR_CONDITION"],#forCond);}
        {String insertion="counter.incCompar()";
          engine.insertAfter(LT(0), insertion)
        }  
;
However this just adds counter.incCompar() to the last comnparative 
operation in the for loop
How can add this bit of text to both, is there an easier way then the 
way I am doing it?
I have tried rewriting some of the expression rules but it seems to add 
the text to just about anything,

Will appreciate any help lads

cheers
ed.










More information about the antlr-interest mailing list