W202 Rule that calls itself at both endsΒΆ
An alternative of a rule begins and ends with the rule itself. The right end takes as much as it can before the left end grows, so a chain of operators groups to the right: 1-2-3 is read as 1-(2-3), where subtraction wants (1-2)-3.
start: sum
sum: left=sum "-" right=sum -> minus | NUMBER
NUMBER: [0-9]+
grammar.fpeg:2:6: warning[W202]: sum calls itself at both ends of this alternative, which groups to the right
Let the rule call itself at one end only: at the left for an operator that groups to the left, at the right for one that groups to the right. The other operand is the next tighter rule. A precedence block says the same for a whole table of operators.
start: sum
sum: left=sum "-" right=NUMBER -> minus | NUMBER
NUMBER: [0-9]+