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

Terence Parr parrt at cs.usfca.edu
Sat Jan 8 11:39:52 PST 2011


hi. search for keyword "imaginary token" or imaginary  node.
Ter
On Jan 8, 2011, at 11:05 AM, r.b.lists at gmx.net wrote:

> 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.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list