Lucien Antlr wrote:
Hi folks,
 
I saw back in 2005 there was a bit of discussion around inline tree building.   ( linked here
http://markmail.org/message/7zigjknpakugflje ).  For practice I am converting the freely available C v2 ANTLR .g  and I came over a rule that has me stuck...
 
It keeps the internal symbol-table by adding part of a tree into the symbol table along with the C symbol (in this case enum).
 
Normally a v2 rewrite would look like below (from stdcparser.g)
 
enumerator[String enumName]
        :       i:ID                { symbolTable.add(  i.getText(),
                                                        #(   null,
                                                            #[LITERAL_enum, "enum"],
                                                            #[ ID, enumName]
                                                         )
                                                     );
                                    }
                (ASSIGN constExpr)?
        ;
#( ) under v2 calls ASTFactory.create(), but under v3 it just appears to pass straight through into the Java target? 
 
This is true even when re-written, as I guessed it should be below.
 
enumerator[String enumName]  
        :       i=ID         { symbolTable.add(  $i.text,
                                                        ^(   NULL,
                                                            ^(LITERAL_enum),
                                                            ^(ID $enumName.text)
                                                         )
                                                     );
                                    }
                (ASSIGN constExpr)?
        ;
The only thing I came up with is "rewriting" the rule, and creating a dummy rule inside and using $dummy.tree inside the action.
 
Any thoughts from the more experienced community?
 
Look at the version that is already converted to v3. It is contained in the examples tar that you can download from the main download page. Look under the Java directory for java examples, C for C examples, etc.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to