[antlr-interest] [C target] Tree parent references not set

Mike Lischke mike at lischke-online.de
Tue Sep 18 05:56:17 PDT 2012


Hey Jim,

there still seems to be a problem with setting the parent for a tree as described by Dimitry (http://markmail.org/message/ykstbb66lqknnvkl). In antrl3basetree.c addChild(..)  the handling of non-nil nodes is not complete. When copying child nodes from the given child node to the new parent tree the parent field of the moved children must be updated as well. Otherwise they all end up with a NULL parent. Here's some parts of my grammar and a dump:

...
logical_xor_expression:
	logical_and_expression (XOR_SYMBOL^ logical_and_expression)*
;
...

String to parse: select A, B, A OR B, A XOR B, ...

Dump:

(1, 0, nil)    nil
	(1, 0, SELECT_SYMBOL [547], address: 0x747b1f0, parent: 0x747b01c)    select
	(1, 0, SELECT_EXPR [546], address: 0x747b460, parent: 0x747b01c)    SELECT_EXPR
		(1, 0, FIELD_REF_ID [212], address: 0x747bebc, parent: 0x0)    FIELD_REF_ID
			(1, 7, IDENTIFIER [259], address: 0x747be20, parent: 0x0)    A
	(1, 8, COMMA_SYMBOL [90], address: 0x747b28c, parent: 0x747b01c)    ,
	(1, 0, SELECT_EXPR [546], address: 0x747b598, parent: 0x747b01c)    SELECT_EXPR
		(1, 0, FIELD_REF_ID [212], address: 0x747c12c, parent: 0x0)    FIELD_REF_ID
			(1, 10, IDENTIFIER [259], address: 0x747c090, parent: 0x0)    B
	(1, 11, COMMA_SYMBOL [90], address: 0x747b328, parent: 0x747b01c)    ,
	(1, 0, SELECT_EXPR [546], address: 0x747b76c, parent: 0x747b01c)    SELECT_EXPR
		(1, 15, OR_SYMBOL [447], address: 0x747b6d0, parent: 0x0)    OR
			(1, 0, FIELD_REF_ID [212], address: 0x747c39c, parent: 0x0)    FIELD_REF_ID
				(1, 13, IDENTIFIER [259], address: 0x747c300, parent: 0x0)    A
			(1, 0, FIELD_REF_ID [212], address: 0x747c4d4, parent: 0x0)    FIELD_REF_ID
				(1, 18, IDENTIFIER [259], address: 0x747c438, parent: 0x0)    B
	(1, 19, COMMA_SYMBOL [90], address: 0x747b3c4, parent: 0x747b01c)    ,
...

Adding setParent() calls to the two child copying branches solves this problem. I also set the child index there (just like freshenPACIndexes does).

Mike
-- 
www.soft-gems.net



More information about the antlr-interest mailing list