2

パーサー文法からツリー文法への移行に問題があります。書き換えルール (->) の代わりにツリー演算子 (^,!) を使用すると問題が発生します。

where_clause
    :   'where'! condition_or
    ;

condition_or
    :   condition_and ( 'or'^ condition_and )*
    ;

condition_and
    :   condition_expr ( 'and'^ condition_expr )*
    ;

condition_expr
    :   condition_comparision
//  |   condition_in
//  |   condition_like
    ;

condition_comparision
    :   column_identifier ('=' | '!=' | '>' | '<')^ sql_element
    ;

上記のパーサー文法の場合、ツリー文法はどのようになりますか? これは再帰的ではないため、ツリー文法でこれを 1 つのルールにまとめることができません。

書き換え構文を使用してパーサー文法を強制的に書き換える別の方法

condition_or
    :   condition_and -> condition_and 
     ( 'or' x=condition_and -> ^('or' condition_or $x))*
    ;

これを行う簡単な方法はありますか?

ありがとう

4

1 に答える 1

2

対応するツリー文法は次のようになります。

where_clause
    :   condition_or
    ;

condition_or
    :   ^('or' condition_and condition_and)
    ;

condition_and
    :   ^('and' condition_expr condition_expr)
    ;

condition_expr
    :   condition_comparision
    ;

condition_comparision
    :   ^('=' column_identifier sql_element)
    |   ^('!=' column_identifier sql_element)
    |   ^('>' column_identifier sql_element)
    |   ^('<' column_identifier sql_element)
    ;
于 2012-05-01T06:37:26.350 に答える