In the production rules of the calculator, the grammar rules for statement, expression and term are kind of awkward and inefficient. They are recursive, which could lead to backtracking, and it's not always easy to get the rules right.
Therefore, Parse::RecDescent has 2 directives, leftop and rightop, which can be used to to describe the behaviour of left associative and right associative operators.
The syntax is:
<leftop: left operator right> <rightop: left operator right>where left, operator and right are items as described earlier.
The return value of such a directive is a reference to an array, whose elements are the values of the items left and right. That is, the value of operator is discarded, except when operator is a rule, or when operand is a regular expression, and the first bracketed expression returns a value (that is, $1 is defined).