[antlr-interest] New User help!

Walter Schilling walter.schilling at computer.org
Thu Jun 29 20:15:36 PDT 2006


I'm just starting to use ANTLR and I've got a question that I think
should be obvious but I have yet to see an answer for.  I'm sure I'm
just looking in the wrong spot.  I'm writing a Java analysis tool that
uses the Java ANTLR grammar.  On various occasions in my design, I need
to take the AST that I have generated and translate / walk that back to
the original text.  For example, if I had the java construct:

if ((x==0) && (y==true))

the AST would be represented as :
if
  EXPR
    &&
      ==
        x
        0
      ==
        y
        true
  { 
...

Given that a portion of my data structure is an AST starting with the
EXPR node, is there any easy way I can walk the tree and regenerate my
original text?  I'm thinking this should be something easy and obvious,
but short of hand coding a java recursive loop (which so far has not
achieved quite what I want, I haven't found an easy way to do this.)  It
feels like there should be some way to use the existing tree walked I
have to do this, but I'm thus far drawing a blank.

Thanks for your assistance,

Walt Schilling

-- 
Walter W. Schilling, Jr.
2004 - 2007 Ohio Space Grant Consortium PhD. Fellowship Recipient
University of Toledo PhD Doctoral Candidate
MSES 1998 University of Toledo
BSEE 1997 Ohio Northern University



More information about the antlr-interest mailing list