[antlr-interest] Best way to describe "order" of AST tree nodes

public.web.josh public.web.josh at gmail.com
Wed Aug 20 22:07:46 PDT 2008


Hello all!

I am creating a grammar file that uses an AST tree as its output. So far, so
good, and I have been excited to learn and use ANTLR. Unfortunately, I have
hit a snag that my limited experience is preventing me from overcoming.

When parsing the input, I can create the specific sub nodes in a tree root
as desired, but I now have the need to mark the order that they appeared in
the input. Specifically, in my case, I am trying to parse something similar
to a multi-dimensional array declaration:

object[x,y,z]

Currently I can produce a tree that looks similar to:

^(OBJECT ^(DIM x) ^(DIM y) ^(DIM z))

My desire is to produce a tree similar to:

^(OBJECT ^(DIM ^(POS 0) ^(SIZE x)) ^(DIM ^(POS 1) ^(SIZE y)) ^(DIM ^(POS 2)
^(SIZE z)))

The closet I got was setting a rule return value to a scope variable that
was incremented as each dimension was processed. This worked well, except
for the fact that I could not figure out a way to get that value into the
tree.

Am I on the right track, or is there an easier way to do this?

Thanks ahead of time for any help you can provide!!

-josh

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


More information about the antlr-interest mailing list