[antlr-interest] Rewrite issue

Ivan Brezina ibre5041 at ibrezina.net
Wed Jun 27 15:17:40 PDT 2012


On 06/26/2012 06:33 PM, Ivan Bludov wrote:
> Hi, Guys
> I'm playing with rewrite feature of ANTLR. So I have a real SQL
> grammar and I'm trying to do something like that.
>
> -------------------------------------------------------------
> 1)
> non_join_query_expression
> 	options {k=1;}
> 	:	(	(non_join_query_term -> non_join_query_term)
> 		|	(
> 		 	joined_table  ( op = UNION | EXCEPT ) ( ALL | DISTINCT )? (
> corresponding_spec  )? query_term  ->
> 		 	joined_table  $op DISTINCT CORRESPONDING  query_term
> 			)
> 		)
> 		(
> 			( op = UNION | EXCEPT ) ( ALL | DISTINCT )? ( corresponding_spec
> )? query_term ->
> 			$non_join_query_expression $op DISTINCT CORRESPONDING  query_term
> 		)*
> 	;
>
>

maybe my answer is off-topic, but anyway.
the word "UNION" is optional therefore the "op" should be optional too.

1st rewrite
->  ^('SOME ROOT TOKEN' joined_table $op? DISTINCT? CORRESPONDING? 
query_term)

2nd rewrite

-> ^('SOME ROOT TOKEN' $non_join_query_expression $op? DISTINCT? CORRESPONDING?  query_term




More information about the antlr-interest mailing list