Skip to content

Tensions in Practice: Bounded local syntax in tension with nested expression

Bracket languages · two explicitly different contracts

A flat message format permits only repeated pairs such as ()[](); every opening must be followed immediately by its matching close. A richer format also permits arbitrarily nested pairs of both types, such as ([()]). The flat reader correctly rejects that message at its second symbol. The nested reader keeps unmatched opening types, then removes them in reverse order as the closing symbols arrive.

Keep syntax checking bounded and local

Use a deliberately flat language with a small, fixed set of reader states.

Express arbitrarily nested typed groups

Allow a group to contain other groups while preserving which opening each close must match.

Why these aims pull against each other

The richer language introduces unmatched context whose depth is not bounded by the language. A fixed local pair rule avoids that memory obligation by excluding nesting, not by pretending to validate it.

Compare the arrangements

Flat pairs

Accept zero or more complete () or [] pairs, with no nesting or other symbols.

Input: ([()]) · read left to right
TokenOpeningsState
Start—NoneReady
Step 1((Need )
Step 2[(Reject
Step 3Not read—Stopped
Step 4Not read—Stopped
Step 5Not read—Stopped
Step 6Not read—Stopped
What it protects
The reader needs only ready, need ), need ], and rejection states; adjacent-symbol and boundary rules suffice.
What it costs
Nested inputs such as ([()]) are intentionally outside the format, even when well-formed under the richer grammar.
When it fits
Flat grouping expresses every required message and rejecting nesting is an explicit contract.

Illustration note: The input is not malformed relative to every language. It is invalid only for this deliberately restricted one; the validator is correct for its stated language.

Nested pairs

Push each opening onto a stack; a close must match the top, which is then removed. Accept at the end only when the stack is empty.

Input: ([()]) · read left to right
TokenOpeningsState
Start—NoneReady
Step 1((Open
Step 2[([Open
Step 3(([(Open
Step 4)([Open
Step 5](Open
Step 6)NoneAccept
What it protects
The shown nested message is accepted with each close matched to the correct most recent opening.
What it costs
Retained opening types grow with nesting depth; practical implementations need a resource limit or explicit failure behavior.
When it fits
Nested typed groups are necessary and their additional parser state is supported.

Illustration note: The Openings column lists bottom to top, with the rightmost symbol most recent. Two bracket types require retaining order, not just a depth count. The finite trace illustrates, rather than proves, the unbounded-language requirement.

What this illustration does—and does not—establish

Local Sequence Legality: Local sufficiency versus non-local legality (scopal) supplies the locality boundary and Local Sequence Legality: Tighter gate versus expressive cost (sign) the expressive cost of restriction. Both grammars and the stack trace are editorial and explicit.

  • Both readers validate syntax only; acceptance does not establish useful, safe or meaningful content.
  • A language with a fixed maximum nesting depth can use bounded state; that is a third, separately declared contract.
  • For only one bracket type, an unbounded counter suffices to track depth; the typed-stack requirement here depends on both () and [].

Source entries

Local Sequence Legality

Prime · Source of the tension

Local Sequence Legality: Local sufficiency versus non-local legality (scopal) supplies the conflict examined here.

Local sufficiency versus non-local legality (scopal)

The prime's signature insight is that local constraints over short windows can do global work — but only up to the locality boundary, beyond which legality requires non-local information (balanced brackets at arbitrary depth, unbounded agreement).

Read the source section

Tighter gate versus expressive cost (sign)

The failure mode is *over-restriction*: narrowing the legal envelope so far that legitimate inputs (a borrowed word's foreign cluster, a valid-but-rare token) are rejected at the boundary, pushing users toward escapes that reintroduce the variety the tightening removed.

Read the source section