[antlr-interest] Irregular AST construction

Mike Lischke mike at lischke-online.de
Wed Jul 4 00:05:57 PDT 2012


Hi,

this might be related to the C target only, but I'm not sure.

Given this rule:

primary:
	(
		literal
		| field_name
		| function_call// -> ^(FUNCTION_CALL function_call)
		| PARAM_MARKER
		| variable
		| PLUS_SYM primary
		| MINUS_SYM primary
		| BITWISE_NOT primary
		| LOGICAL_NOT primary
		| BINARY_SYM primary
		| ROW_SYM expression_list
		| EXISTS_SYM subquery
		| match_expression
		| case_expression
		| interval_expression
	)
	(options {greedy = true;}: COLLATE_SYM identifier)*
;
  
I see a completely different tree construction in the generated parser depending on whether I enable the single (out-commented) rewrite rule or not. If I leave it out then everything is ok. With it, though, the generated code switches to using local streams for each alternative, but does not create the root_0 node (except for the function_call alternative). As a consequence the primary() function returns an empty tree for most of the alternatives.

So far I had not the impression that I have to add a rewrite rule to every alternative if I have one that has a rule. Is this a bug in code generation or should I now think to add a rule to all alternatives in such scenarios?

Mike
-- 
www.soft-gems.net



More information about the antlr-interest mailing list