Skip to content

Simple Precedence Grammar

Use conflict-free precedence relations between grammar symbols to locate reducible handles.

Version
v1 · 2026-10-04 · History
Domain-specific #
13771
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Compiler Theory → Computer Science & Software Engineering
Aliases
Simple-precedence grammar, Wirth–Weber simple precedence grammar

Core Idea

A simple precedence grammar is a context-free grammar whose production-derived yields, equal and takes-precedence relations do not conflict for any ordered pair of grammar symbols. A table of these relations can locate reducible phrases for bottom-up parsing. In the operational convention used here, right-hand sides must also be nonempty and unique so a located phrase identifies one reduction. Hladký defines the conflict-free class first and imposes right-side uniqueness separately for an unambiguity theorem.[1][2]

How would you explain it like I'm…

One Rule for Each Pair

Imagine reading a sentence and, for every two neighbors side by side, having one clear rule: they are in the same chunk, a new chunk starts here, or a chunk ends here. With those rules a computer can find little chunks and fold them into bigger ones, like snapping blocks together. A simple precedence grammar is a set of language rules where every pair of neighbors gets only one answer, never two.

One Answer per Neighbor Pair

Computers read programs using grammar rules, a bit like rules for building sentences. One way to read is bottom-up: find a small piece that matches a rule and replace it with the rule's name, over and over. A simple precedence grammar makes this easy. For each pair of symbols that can sit next to each other, the rules give at most one of three relations: "a piece starts here," "same piece," or "a piece ends here." Those marks show exactly where the next piece to replace begins and ends. Also, no two rules have the same right side, so once the piece is found, the computer knows which rule to use.

Conflict-Free Precedence Grammar

A simple precedence grammar is a context-free grammar designed for bottom-up parsing, where the parser builds up a structure from the input by repeatedly finding and reducing a 'handle', the next piece that matches the right-hand side of a rule. For every ordered pair of grammar symbols (both terminals and nonterminals), the grammar defines at most one of three Wirth–Weber relations: yields (a handle starts), equal (same handle), or takes precedence (a handle ends). Some pairs have no relation. The table of relations lets the parser mark where a handle begins and ends. Under the convention used here, rule right-hand sides are nonempty and no two rules share the same right-hand side, so each found handle reduces in only one way. Some sources call just the no-conflict table property 'simple precedence' and treat unique right-hand sides as a separate condition.

 

A simple precedence grammar is a context-free grammar whose productions induce at most one of the three Wirth–Weber precedence relations (yields ⋖, equal ≐, takes precedence ⋗) for each relevant ordered pair of grammar symbols, terminals and nonterminals alike; some pairs may have no relation. The resulting relation table delimits the handle, the reducible phrase, during shift-reduce (bottom-up) parsing: ⋖ marks its left edge, ≐ its interior, and ⋗ its right edge. Under the operational convention adopted here, right-hand sides are nonempty and no two productions share a right-hand side, so each identified handle maps to exactly one reduction. Definitions differ at this boundary: a 1972 formal-language paper calls the conflict-free relation property alone 'simple precedence' and states right-hand-side uniqueness separately for its unambiguity theorem. The distinction matters because a conflict-free matrix locates phrase boundaries, whereas determining which nonterminal replaces the phrase requires the inverse production lookup to be unique.

Scope of Application

The class is used in formal-language and compiler theory to characterize grammars suited to local precedence-table parsing. It compares terminals and nonterminals, unlike operator precedence's narrower terminal-focused scheme. The condition belongs to a particular grammar's form; failure of one expression grammar does not by itself prove that its language has no equivalent precedence grammar.[1][3]

Clarity

The table labels neighboring symbols with one of three relations. A takes-precedence boundary prompts a reduction; scanning back to a yields-precedence boundary locates the handle, and a matching production supplies the replacement nonterminal. Two different labels for the same ordered pair would make this simple local choice unavailable.[1][3]

Manages Complexity

The relation matrix turns a potentially deep derivation into local shift/reduce decisions. The construction cost shifts into computing a conflict-free table and, for a conflicting grammar, possibly rewriting its presentation or choosing another parser; the cited sources do not quantify that cost or prove an easy universal rewrite. A unique boundary does not settle which production to apply if two rules share the same right side. That is a separate correctness premise under the operational convention, not a tradeoff. The constructed bracket matrix below was independently checked against Oberlin's rules; it is not a source-published example.[1][3][2]

Abstract Reasoning

Oberlin notes work a recursive grammar S→Aab; A→aS|c and show its conflict-free table. For a smaller constructed example, S→[S]|a, the author-derived left/right sets are L(S)={[,a} and R(S)={],a}; the six occupied pair cells are [=S, S=], [<[, [<a, ]>], and a>], with no pair conflict and distinct nonempty right sides. The derivation was independently checked against the published rules, but the example itself is not published. Neither example proves that all recursive languages are simple precedence.[1]

Knowledge Transfer

The live Context-Free Grammar identity is the strict parent: every simple-precedence grammar retains context-free productions and adds a conflict-free all-symbol relation test, with the stated operational right-side restrictions. The same relation construction can test different context-free grammars once productions are explicit. What does not transfer automatically is an easy grammar transformation, table size, or a theorem about an entire language class from one chosen grammar.[1][3]

Relationships to Other Abstractions

Local relationship map for Simple Precedence GrammarParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Simple PrecedenceGrammarDOMAINDomain-specific abstraction: Context-Free Grammar — is a kind ofContext-FreeGrammarDOMAIN

Current abstraction Simple Precedence Grammar Domain-specific

Parents (1) — outgoing typed relations

  • Simple Precedence Grammar is a kind of Context-Free Grammar Domain-specific

    A simple-precedence grammar is a context-free grammar with conflict-free all-symbol precedence relations.

Hierarchy paths (2) — routes to 2 parentless roots

Neighborhood in Abstraction Space

Simple Precedence Grammar sits in a moderately populated region (47th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.

Family — Formal Models & Logical Foundations (38 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Oberlin College CS 331, “Precedence Grammars”, pp.8–13. registry ↩a ↩b ↩c ↩d ↩e ↩f

[2] Miroslav Hladký, “Precedence Relations and Their Connection with Unambiguity of Context-free Grammars”, Kybernetika 8(1) (1972), Definition 2.3 and Theorem 2.1. registry ↩a ↩b

[3] Watson, Des, “Compilers”, January 2009, §§5.2.4–5.2.6. registry ↩a ↩b ↩c ↩d