Tous les livres

Professionnel

Applis À propos Coach Connexion Commencer la lecture

Computer Science · Glossaire

Qu'est-ce que « Binding power, precedence climbing » ?

Aussi appelé : binding power · precedence climbing

Definition 2.9 University Computer Science — Year 3 · Chapitre 2 — Top-Down Parsing

The binding power of a binary operator is a positive integer, higher for operators that bind more tightly: in Moor, 1 for ||, 2 for &&, 3 for == and !=, 4 for the comparisons, 5 for + and -, 6 for *, / and %. Precedence climbing parses an expression whose operators all have binding power at least mm as follows: parse an operand; then, while the next token is an operator of power p≥mp \ge m, consume it, parse the right operand as an expression of minimum power p+1p + 1, and combine.

Call trees for a + b * c. Left: one function per level of ||, &&, equality, comparison, sum, product, then the prefix operators and the primary. Right: the parser of , where the right side of + is parsed with minimum power 6 and that of * with 7.
Call trees for a + b * c. Left: one function per level of ||, &&, equality, comparison, sum, product, then the prefix operators and the primary. Right: the parser of Listing 2.6, where the right side of + is parsed with minimum power 6 and that of * with 7.
Lire dans le chapitre →