[antlr-interest] Improving Tree Walker Execution for Loops
catharinaamber
awinkler at indra.com
Tue May 7 16:10:17 PDT 2002
Hi,
I'm looking for suggestions for how I can improve execution time for
loops in my tree walker. Here are the statements for my while loop:
while_statement :
#(WHILE a : CONDITION
{
in_loop = true;
while (1 == while_condition(a, 1))
{}
in_loop = false;
}
)
;
while_condition[int f] returns [int yes]
{
yes = 0;
} :
c : CONDITION cb : CODE_BLOCK
{
yes = cond (c)->getInt();
#ifdef EVALUATOR_DEBUG
cout << "f = " << f << " yes = " << yes << endl;
#endif
if (f == yes)
{
try
{
code_block (cb);
}
catch (BreakStatementException &ex)
{
// If there is a break statement in the loop, exit.
yes = 0;
}
catch (ContinueStatementException &ex)
{
// If there is a continue statement in the loop,
// continue to the test/condition. Nothing happens
// here, we just catch the exception that stops
// the loop control flow.
}
}
}
;
code_block returns [Value *ret_val]:
#(CODE_BLOCK ret_val = statement)
{
#ifdef EVALUATOR_DEBUG
cout << " code_block return val: " << *ret_val << endl;
#endif
}
;
The syntax is like C. The loops typically iterate 2000 times, and
there are 25+ loops.
Thanks for any suggestions.
--Anna
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list