[antlr-interest] Q: move from v2 to v3 parser grammar. Rewrite tree rule

Kevin J. Cummings cummings at kjchome.homeip.net
Tue Mar 22 11:20:52 PDT 2011


On 03/22/2011 02:11 PM, Ruslan Zasukhin wrote:
> On 3/20/11 1:11 PM, "Matt Fowles" <matt.fowles at gmail.com> wrote:
> 
> Hi Matt,
> 
>> Ruslan,
> 
>> Try:
>>
>> query_expression
>>     :    query_term (( "union" | "except" )^ "all"? query_term)*
>>          -> ^(QUERY_EXPRESSION $query_expression)
>>     ;
> 
> Well,  $  not helps.   Still same
>        error 165 uses rewrite syntax and also an ast operator
> 
> As I understand, 
>     ->   is re-write syntax
>     ^    is AST operator ...

Sounds like ANTLR is being picky and not letting you mix both AST
construction and rewrite rules in the same production.  You *could* try
the following:

query_expression
	:	qe -> ^(QUERY_EXPRESSION $qe)
	;

qe      :	query_term (( 'union' | 'except' )^ 'all'? query_term)*
	;

Now one rule has the AST construction, and the other the rewrite rule.

-- 
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list