我有以下模棱两可的语法,其中大写字母规则适用于简单的词汇标记:
program : function | function program
function : FN ID ARROW TYPE invariants DASH block
fn_call : ID L_PAREN CONSTANT R_PAREN
invariants : invariant | invariant invariants
invariant : TYPE ID COLON invariant_tests
invariant_tests : test | test COMMA invariant_tests
test : OPERATOR CONSTANT | STAR
block : expression | expression block
expression : loop | fn_call | assignment | def | constant
loop : FOR def IN CONSTANT COLON block
assignment : ID ASSIGN CONSTANT | ID ASSIGN ID
def : TYPE assignment
我收到 8 个 shift/reduce 错误(使用 Python 2.7 和 PLY 时)。
歧义是我如何定义“一个或多个”的结果,例如。block : expression | expression block
?