[antlr-interest] create a tree with an ID token in the C runtime...
Robert Soule
robert.soule at gmail.com
Wed Mar 11 14:54:58 PDT 2009
Hi,
Sorry to keep spamming this list with my problems.
I am trying to create an ID node that is usually recognized by the
lexer by hand.
I create my node in the following way:
pANTLR3_STRING_FACTORY strFactory = antlr3StringFactoryNew();
pANTLR3_BASE_TREE_ADAPTOR ADAPTOR = ANTLR3_TREE_ADAPTORNew(strFactory);
MyParser_compilationUnit_return retval;
pANTLR3_BASE_TREE compilationUnit =
(pANTLR3_BASE_TREE)ADAPTOR->createTypeText(ADAPTOR, COMPILATIONUNIT,
NULL);
// create some more pANTLR3_BASE_TREE instances...
pANTLR3_COMMON_TOKEN token = ADAPTOR->createToken(ADAPTOR, ID,
(pANTLR3_UINT8)"Sample");
pANTLR3_BASE_TREE id =
(pANTLR3_BASE_TREE)ADAPTOR->create(ADAPTOR, token);
// add children using calls like: ADAPTOR->addChild(ADAPTOR,
compilationUnit, <trees>);
retval.tree = compilationUnit;
Later, though, when I try to print, I am getting a crash:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000004
0x00004503 in pt (ctx=0x803800, t=0x2b81f0) at Printer.cpp:16642
16642 cout << t->getText(t)->chars;
(gdb)
I don't see what I'm doing wrong when I am creating my AST. I've been looking at
the documentation, and the source itself, but I can't figure out what
I did wrong..
When I print the tree I constucted with
ast.tree->toStringTree(ast.tree)->char, I see:
( ( ( ) ))
but I expect:
( ( ( Sample ) ))
thanks,
Robert
More information about the antlr-interest
mailing list