我对SABLECC有这个(工作)LALR语法:
Package org.univpm.grail.sable;
Helpers
digit = [ '0' .. '9' ];
letter = [ [ 'a' .. 'z' ] + [ 'A' .. 'Z' ] ];
any_character = [ 0 .. 0xfffff ] ;
States
normal, complex;
Tokens
newline = ( 13 | 10 | 13 10 ) ;
blank = 32+ ;
dot = '.' ;
comma = ',' ;
element = 'v' | 'V' | 'e' | 'E' | 'all' | 'ALL' ;
cop = '>' | '<' | '>=' | '<=' | 'like' | 'LIKE' | '==' | '!=' ;
number = digit+ | digit+ '.' digit digit? ;
l_par = '(' ;
r_par = ')' ;
logic_and = 'and' | 'AND' ;
logic_or = 'or' | 'OR' ;
logic_not = 'not' | 'NOT' ;
id = ( 95 | letter ) ( letter | digit )+ ;
line_comment = '/' '/' [ any_character - [ 10 + 13 ] ]* ( 13 | 10 | 10 13 ) ;
string = '"' letter* '"' ;
Ignored Tokens
blank;
Productions
phrase =
{instruction} instr |
{complex_instruction} instr newline+ phrase? ;
instr = command query ;
command =
{identifier} id |
{complex_identifier} id l_par parlist r_par ;
parlist =
{complex_parlist} par comma parlist |
{simple_parlist} par ;
par =
{numero} number |
{stringa} string |
{idpar} id ;
query =
{query_or} query logic_or term |
{query_term} term ;
term =
{term_and} term logic_and factor |
{term_factor} factor ;
factor =
{atop} attroperator |
{query_not} logic_not attroperator |
{query_par} l_par query r_par ;
attroperator =
{simple_element} element |
{complex_element} element dot id cop par ;
我试图将其转换为使用ANTLR(LL解析器生成器)的XText。我无法转换这两个左递归规则:
query =
{query_or} query logic_or term |
{query_term} term ;
term =
{term_and} term logic_and factor |
{term_factor} factor ;
我该怎么办?我认为我应该使用运算符优先级,但现在我不能只用 LL方式思考。