Child pages
  • Binding power syntax
Skip to end of metadata
Go to start of metadata

In order to specify binding power we use "^" which is power symbol:

Here is sample from Calculator grammar:


Binding power controls how to resolve ambiguities in parsing rules when text parsed with one rule can be prefix or suffix of text parsed with another rule. Since this problem is most frequently arise in expressions, it can be formulated as this: "Given an operand between two operators, is the operand bound to the left operator or the right?". Hence the name, "binding power".

When checking alternatives for a subrule, we will only consider rules with power higher than power of subrule currently being parsed, and prefer them if match is found. In "1 + 2 * 3", if "+" has a BP of 10 and "*" of 20, the "2 * 3" part will be preferred and its result passed as a right expression to the first "+".

  • No labels