[antlr-interest] Newby - How to find rule context in the AST

Gavin Lambert antlr at mirality.co.nz
Sun May 27 05:12:20 PDT 2007


At 21:16 27/05/2007, Harris, Tobin wrote:
>The problem is, I want to be able to interrogate the tree to find 
>out if, for example, the [credentials] were parsed, and then loop 
>through the sub-nodes (username, password etc). Unfortunately the 
>AST doesn't contain this information. I can get the type of a 
>node, but that will only be a "DIGIT" or "INT" etc.
>
>Is there a way of retaining more of the parse tree? Am I missing 
>something here?

Read up on tree rewrite rules (either in the book or the 
wiki).  You can create fake tokens with semantic meaning but no 
syntax (no direct rules) and then use them as the root node in a 
generated AST subtree (or anywhere else for that matter, but the 
root is the most common place).



More information about the antlr-interest mailing list