[antlr-interest] Bug for C-Target on $tree usage

Christian Hoffmann Sanus at gmx.de
Wed Nov 26 14:42:21 PST 2008


Hello,

converting from antlr2 to antlr3 becomes a horror! ;-)


Now I am tumbling over some c-codegeneration.
Don't know if its me or a real bug...


declaration
        :       declSpecifiers variableDeclarations
                        -> ^(TOK_VAR_DEF declSpecifiers variableDeclarations)
                { m_Symbols.AddVarDef($tree); }   // add the variable
                                      ^^^^problem is here
        ;


should result to somthing like
                { m_Symbols.AddVarDef(retval.tree); }   // add the variable

instead the resulting c-code becomes
            m_Symbols.AddVarDef(((pANTLR3_COMMON_TOKEN)retval).tree);  );

2 Bugs in one line!
1. bug: retval.tree is not a pANTLR3_COMMON_TOKEN, its of type pANTLR3_BASE_TREE

Bugfix??: C.stg lines 3013 and 3035 ??
line 3013> rulePropertyRef_tree(scope,attr) ::= "retval.tree"
line 3050> ruleSetPropertyRef_tree(scope,attr,expr) ::= "retval.tree=<expr>;"

2. bug:
      original code:
      ADAPTOR->addChild(ADAPTOR, root_0,  pVMCompiler->m_Symbols.AddVarDef(((pANTLR3_COMMON_TOKEN)retval).tree); );
      look at the end of the line,
      somthing like func(... func(...); ); would not compile ;)
Bugfix:
Swapping the lines helps, but...
declaration
        :       declSpecifiers variableDeclarations
                { m_Symbols.AddVarDef($tree); }   // add the variable
                        -> ^(TOK_VAR_DEF declSpecifiers variableDeclarations)
        ;


Thx in advance for your comments...


---
Christian Hoffmann
D-38118 Braunschweig



More information about the antlr-interest mailing list