[antlr-interest] Pruning the Parse Tree

Guntis Ozols guntiso at latnet.lv
Mon Mar 10 15:40:14 PDT 2008


> 3.  I'm more interested in the overall code orgainzation.  I don't need a
> letter-perfect grammar; I just need ANTLR to properly identify the parts of
> code.  There are only specific nodes I am interested in.

So move only nodes you are interested in up, leave everything else out
or as is (flat). It is very easy to convert nodes to parent nodes.
For example, to get function names, you change

functionCall:	functionName '(' ( argument (',' argument)* )? ')';

to

functionCall:	functionName '(' ( argument (',' argument)* )? ')'
		->	^(functionName argument*);

which gives you AST without parentheses and commas for function calls,
where arguments are children of function names.

> I was hoping there would be some kind of information in each node
> that would state what rules were actually used vs. what rules were
> looked at.

ANTLRWorks uses different colors for these, so there must be some way
to get this info.

> > > Both are found in the final parse tree, and I need to
> > > get rid of the superfluous nodes.  I don't know if this
> > > is default antlr behavior or if this is a bug.
> >
> > Why do you need parse tree?
> > How about using syntax tree?

P.S. Use 'Reply to all' in your mailer, you will get more answers, probably :)

Guntis



More information about the antlr-interest mailing list