Tensions in Practice: Simple evaluation order in tension with familiar precedence¶
An invented expression reader with an ambiguous grammar
Suppose an expression grammar permits either grouping of 2 + 3 × 4. A left-to-right policy groups (2 + 3) × 4 and yields 20. A multiplication-first policy groups 2 + (3 × 4) and yields 14. Both accept the same tokens; recognition alone does not choose the tree. A language must publish a policy or require explicit parentheses.
Use a uniform operation order
Apply the same left-to-right convention to every operator.
Honor established precedence
Keep multiplication grouped before addition.
Why these aims pull against each other
The same unparenthesized message cannot deliver both meanings. A familiar convention for one audience can surprise another.
Choose an arrangement to see what changes and what remains difficult.
Arrows express the stated dependencies or transformations, not measured effects. All example quantities are invented.
What this choice protects
What it costs
When it fits
Compare the arrangements
Read left to right
Use the explicitly declared left-to-right policy.
- What it protects
- One uniform operation-order rule is available.
- What it costs
- Readers expecting ordinary arithmetic precedence will obtain a different answer.
- When it fits
- Fits a language or device that clearly specifies this convention and trains its users.
Illustration note: This is a language policy, not a claim that ordinary arithmetic yields 20.
Multiply before adding
Use the explicitly declared multiplication-first policy.
- What it protects
- The result matches common arithmetic precedence.
- What it costs
- A hierarchy of operator priorities must be learned and implemented.
- When it fits
- Fits a contract using that convention; mixed conventions need explicit translation or parentheses.
Illustration note: Neither the token stream nor grammatical acceptance alone selects the policy.
What this illustration does—and does not—establish
The source supplies the tension. The invented setting, alternatives and any numbers illustrate a limited comparison; each arrangement retains its stated costs and conditions.
- The grammar is intentionally declared ambiguous before the policy is applied.
- This finite parse tree does not establish comparative runtime performance or language-wide tractability.
- Parentheses could remove ambiguity but impose additional authoring; they are outside the two selected policies.
Source entries
Parsing
This source passage supplies the contextual tension. The concrete arrangements and schematic examples are editorial illustrations, not measured findings.
Recognition versus Disambiguation (where the real work hides)
Deciding whether a sequence is well-formed is the easy half; the hard, interpretation-laden half is choosing among the multiple legal parses an ambiguous grammar admits. The prime's load-bearing claim is that substantive meaning lives at the disambiguation step, not the recognition step. The failure mode is building a parser that accepts the input and then treating the *first* or *greedy* parse as canonical, smuggling an unexamined interpretive policy in as if it were mechanical.
The source operation
Parsing is the operation of *recovering hidden hierarchical structure from a flat sequence by matching it against a generative grammar*. It takes three things: a *sequence* of tokens (characters, words, notes, nucleotides, events, actions); a *grammar* — a finite system of production rules specifying how legal sequences may be assembled from sub-structures; and an *output structure* — typically a tree (or richer object) recording which rules were applied to which spans. The parser's task is to invert the generative direction: given that the sequence was, or could have been, produced by the grammar, recover the structure that produced it. Where several structures are compatible — *ambiguity* — the parser must return all of them, prefer one by a disambiguation policy, or fail.