[antlr-interest] Unfolding of loops with antlr?

Jon Schewe jpschewe at mtu.net
Tue Dec 18 17:06:42 PST 2007


I've got something I'd like to do with antlr and I'm not sure it's
possible.  I want to unfold loops with antlr inside the parser.  The
idea is this, say I've got an input file like below.  Now antlr has
given me the ability to write nice rules to parse this language and to
do various actions on each rule.  What I'd really like to do is to be
able to tell antlr to repeat a rule action on the same input stream
multiple times while I change some data outside.  Another option would
be for me to be able to duplicate a set of tokens during parsing.  Say
if I know the set of tokens between LOOP and END, could I tell antlr to
duplicate that set of tokens 10 times (since the loop goes from 1 to 10)
with an extra token added in to tell me the loop index during the
initial parse and then let the tree parser just walk the tree?

I'm sure I could hand the AST off to some custom method to do it, but
that seems like I'm duplicating what antlr is already doing in the tree
parser.

Params
i 5;

Variables
x[i];
y;

Constraints
LOOP index 1...10:
  loop[index]:
  f[index] = 10 * x[index];
END

simple:
g = 5 * y;

-- 
Jon Schewe | http://mtu.net/~jpschewe
If you see an attachment named signature.asc, this is my digital
signature.
See http://www.gnupg.org for more information.

For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39



More information about the antlr-interest mailing list