[antlr-interest] Access token tree on rewrite rules

Jose María Chumo Mata jmchuma at gmail.com
Wed Apr 28 04:46:49 PDT 2010


Hello.
I'm writing to ask how I can access a token tree on rewrite rules. Let
me explain the situation. I have a couple of rules that look like
this:

firstRule :
    A^ {$A.tree.doSomething();} secondRule
  | B^ {$B.tree.doSomething();} thirdRule
;

secondRule :
    C { $C.tree.doSomething();} optionalRule? USELESS fourthRule* USELESS
    -> optionalRule? ^(C fourthRule*);

The thing works for the first rule (it call the doSomething() method
of the tree) but it doesn't on the second one because the tree is
null. I've read the code generated by ANTLR and I've realized that on
rewrite rules it creates the trees for the taken later on. Is there a
way to access those trees?

Thanks and sorry for my misspelling.


More information about the antlr-interest mailing list