[antlr-interest] Abstract syntax tree

Marcel Cerveny mcerveny at gmail.com
Wed Feb 23 05:22:17 PST 2005


Hello there!

I was plying with ANTLR for a few days. At this moment i can more or
less parse the files I want to.
However, the structure of AST seems to me quite awkward. The parsing
is just the beginning if the journey. I was hoping that AST will give
me the possibility to check and search for element by referring to the
names i specified in .g file. And possibly to allow me to check
whether or not the optional tokens "i.e (SCOPE)?" are present.
Maybe I need to create another structure in memory during runtime. I don't know.

Here is what I'd like to have. I parse a standard shape interface file:
public interface ITest {
 int a = 1;
 ...
}

Accordingly, I have in the parser spec something like this:
interf : (scope)? I_IDENT! IDENTIFIER^ (body) ;
scope : (PUBLIC|PRIVATE) ;
body : ...

I was hoping for structure like this:
interf
   |_ ITest
         |_ scopeConditional
              |_ present: bool
              |_ scope: private/public
...
Thus, I could do something like
if (interf.scopeConditional.present) {
 ...
}

Can anyone wake me up and give me some hints or put me to the right track?
Thanx in advance.

Marcel


More information about the antlr-interest mailing list