我正在尝试使用 JFlex 和 Cup 编写解析器,但是我在处理递归指向符号时遇到了一些问题,例如使用递归属性访问的函数调用,例如:
var x = obj.property1.functionCall(p1, p2).property2;
这是相关的解析器定义:
unary_exp ::= postfix_exp
| ADD2 unary_exp
| SUB2 unary_exp
| unary_operator unary_exp;
unary_operator ::= ADD
| SUB
| BIT_NOT
| NOT;
postfix_exp ::= primary_exp
| postfix_exp LPAR_SQ right_value_exp RPAR_SQ
| postfix_exp LPAR optional_postfix_exp_list RPAR
| postfix_exp DOT postfix_exp
| postfix_exp SUB2
| postfix_exp ADD2;
primary_exp ::= BOOL
| STRING
| INTEGER
| NUMBER
| NULL;
我得到了以下班次/减少冲突:
Warning : *** Shift/Reduce conflict found in state #190
between postfix_exp ::= postfix_exp DOT postfix_exp (*)
and postfix_exp ::= postfix_exp (*) LPAR optional_postfix_exp_list RPAR
under symbol LPAR
Resolved in favor of shifting.
Warning : *** Shift/Reduce conflict found in state #190
between postfix_exp ::= postfix_exp DOT postfix_exp (*)
and postfix_exp ::= postfix_exp (*) LPAR_SQ right_value_exp RPAR_SQ
under symbol LPAR_SQ
Resolved in favor of shifting.
Warning : *** Shift/Reduce conflict found in state #190
between postfix_exp ::= postfix_exp DOT postfix_exp (*)
and postfix_exp ::= postfix_exp (*) DOT postfix_exp
under symbol DOT
Resolved in favor of shifting.
Warning : *** Shift/Reduce conflict found in state #190
between postfix_exp ::= postfix_exp DOT postfix_exp (*)
and postfix_exp ::= postfix_exp (*) ADD2
under symbol ADD2
Resolved in favor of shifting.
Warning : *** Shift/Reduce conflict found in state #190
between postfix_exp ::= postfix_exp DOT postfix_exp (*)
and postfix_exp ::= postfix_exp (*) SUB2
under symbol SUB2
Resolved in favor of shifting.
Error : *** More conflicts encountered than expected -- parser generation aborted
有人可以向我解释如何处理这些冲突,或者在哪里可以找到使用 java cup、yacc 或 bison 的工作示例?