Message-ID: <68536397.5041.1643397093329.JavaMail.tomcat@c1f7e022e35d> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_5040_276505215.1643397093328" ------=_Part_5040_276505215.1643397093328 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Binding power syntax

Binding power syntax

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

=20

Here is sample from Calculator grammar:

=20
=20
syntax expr
{
| num        =3D number
| rounds     =3D '(' expr ')'
| add        =3D expr sm '+' sm expr  { precedence 10;  }
| sub        =3D expr sm '-' sm expr  { precedence 10;  }
| mul        =3D expr sm '*' sm expr  { precedence 20;  }
| div        =3D expr sm '/' sm expr  { precedence 20;  }
| mod        =3D expr sm '%' sm expr  { precedence 20;  }
| pow        =3D expr sm '^' sm expr  { precedence 30 right-associative; =
}
| neg        =3D '-' expr             { precedence 100; }
| prefixDec  =3D "--" expr            { precedence 200; }
| postfixDec =3D expr "--"            { precedence 200; }
| cond       =3D Condition sm '?' sm  expr sm  Colon=3D':' sm expr=20
| coalescing =3D expr ^401 sm "??" sm expr ^400
}
=20
=20

???

=20
=20

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 anoth= er rule. Since this problem is most frequently arise in expressions, it can= be formulated as this: "Given an operand between two operators, is th= e operand bound to the left operator or the right?". Hence the name, &= quot;binding power".

=20

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

= =20
------=_Part_5040_276505215.1643397093328--