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

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Tue Mar 22 12:35:47 PDT 2011


On 3/22/11 8:11 PM, "Ruslan Zasukhin" <ruslan_zasukhin at valentina-db.com>
wrote:

IF to remove  ^      ( "union" | "except" )^

query_expression
     :    query_term (( "union" | "except" ) "all"? query_term)*
          -> ^(QUERY_EXPRESSION $query_expression)

 then all looks correct, but tree is empty from $query_expression

TREE: (SQL_STATEMENT QUERY_EXPRESSION)

But it should looks as

TREE: (SQL_STATEMENT (QUERY_EXPRESSION (select (SELECT_LIST
(SELECT_ELEM_LIST ) (from (NON_JOIN_TABLE t1)))))


> 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 ...
> 
> 
>  
>> Matt
>> 
>> On Sun, Mar 20, 2011 at 10:40 AM, Ruslan Zasukhin
>> <ruslan_zasukhin at valentina-db.com> wrote:
>>> Hi All,
>>> 
>>> In v2 grammar we have rule as
>>> 
>>> ===========================================
>>> query_expression
>>>    :    query_term (( "union"^ | "except"^ ) ( "all" )? query_term)*
>>>        {    ## = #([QUERY_EXPRESSION,"QUERY_EXPRESSION"], ##);    }
>>>    ;
>>> ===========================================
>>> 
>>> 
>>> We try change it to v3
>>> 
>>> ===========================================
>>> query_expression
>>>    :    query_term (( "union"^ | "except"^ ) ( "all" )? query_term)*
>>>            ->(QUERY_EXPRESSION  ???? )
>>>    ;
>>> ===========================================
>>> 
>>> Ops, we cannot specify top node, because it can be  union OR except.
>>> 
>>> 
>>> For now the only way we have found is:
>>> ===========================================
>>> query_expression
>>>    :    query_expression2  ->(QUERY_EXPRESSION  query_expression2)
>>>    ;
>>> 
>>> 
>>> query_expression2
>>>    :    query_term (( "union"^ | "except"^ ) ( "all" )? query_term)*
>>>    ;
>>> ===========================================
>>> 
>>> 
>>> 
>>> Question is. May be exists more elegant way for v3
>>> Without additional rule?
> 

-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the antlr-interest mailing list