错误(211):[致命]规则条件具有非LL(*)

时间:2013-11-28 22:26:28

标签: antlr grammar antlr3 antlrworks

我使用ANTLR创建语法,但是我收到了这个错误

error(211): [fatal] rule conditions has non-LL(*)  decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

我的语法规则:

conditions
    :    '(' conditions ')' 
    |     condition (C_BINARY_OPERATOR conditions)?   
    ;
condition
    :   expression C_CONDITIONAL_OPERATOR expression
    ;

expression
    :   (term) (('+'|'-')  term)*
    ;

term
    :   (factor) (('*' | '/') factor)*
    ;

factor
    :   C_ID
    |   C_NUMBERS
    |   '(' expression ')'
    ;

// Binary Operators for Logical Calculation 
C_BINARY_OPERATOR
    :   '&&'
    |   '||'
    ;

// Conditonal Operators
C_CONDITIONAL_OPERATOR
    :   '>'
    |   '<'
    |   '=='
    |   '!='
    |   '=<'
    |   '=>'
    ;

如何解决此错误?

2 个答案:

答案 0 :(得分:1)

嗯,错误确实说“通过左因子分解或使用语法谓词或使用backtrack = true选项来解析”。那令人困惑吗?

答案 1 :(得分:1)

在ANTLR网站上查看此page。它包含有关如何修复错误的信息。