[antlr-interest] adding a subtree to the left side of a rewrite rule which doesn't have a corresponding left side element ?

r.b.lists at gmx.net r.b.lists at gmx.net
Sat Jan 8 11:05:46 PST 2011


Hello All,

Sorry for the confusing title...

I'm trying to build an AST via rewrite rules.

The input is a DSL which contains a number of possible constructs, 
including a description of state transitions.

I'd like to build a list 1of all the states mentioned and include that 
list in the AST as something like ^( SL states+ )

What is the best way to do this?

I tried to build a separate rule to extract the states from the input 
and insert it at the right side, but Antlr complains about referencing 
something on the right side which doesn't show up on the left side...

example:

program : bla1 bla2 bla3 -> ^( 'P' bla1 bla2 newSubTree bla3 ) ;

leads to an error...

Then i tried to set up a global scope and collect all the names in it , 
but i didn't find a way to transfer the list into a subtree from within 
the grammar...

Do i really have to build the sub-tree by hand and include it manually, 
or is there a more efficient way?

Thanks,
R.


More information about the antlr-interest mailing list