[antlr-interest] Actions in AST rewrite rules in C

Heiko Folkerts heiko.folkerts at david-software.de
Tue May 31 05:42:49 PDT 2011


Hi all,
I am trying to add a imaginary Token while parsing an AST. The tricky par is that I need to set the text of the imaginary token or node from the result of a C++-Method.
How should this be made right - adding the imaginary node in the rewrite rule and setting the text within an action?

Here is my current rule:
step: ^(STEP stepcontents?) ->
{
pANTLR3_BASE_TREE pStep = $STEP;
pANTLR3_BASE_TREE pStepContents = (pANTLR3_BASE_TREE)pStep->getChild(pStep,0);
if(pStepContents)
{
char* code = createCStringPlain(ParserHelper::getCodeTranslation(CodeTranslationID(1), QString((char*)pStepContents->getText(pStepContents)->chars)));
pANTLR3_BASE_TREE pCode = (pANTLR3_BASE_TREE)ADAPTOR->createTypeText(ADAPTOR,STEPCODE,
(pANTLR3_UINT8) code);
pStep->addChild(pStep,pCode);
}
} 
;
T
Hx in advance


Mit freundlichem Gruß

Heiko Folkerts

-- 
_______________________________________________________

DAVID Software GmbH · Wendenring 1 · 38114 Braunschweig

Tel.: +49 531 24379-14
Fax.: +49 531 24379-79

E-Mail: mailto:heiko.folkerts at david-software.de
WWW:    http://www.david-software.de

Eintragung: Amtsgericht Braunschweig, HRB 3167
Geschäftsführer: Frank Ptok 
_______________________________________________________


More information about the antlr-interest mailing list