encyclopegia.org

Syntactic predicate

A syntactic predicate specifies the syntactic validity of applying a production in a formal grammar and is analogous to a semantic predicate that specifies the semantic validity of applying a production.[src] It is a simple and effective means of dramatically improving the recognition strength of an LL parser by providing arbitrary lookahead.[src] In their original implementation, syntactic predicates had the form “( α )?” and could only appear on the left edge of a production.[src] The required syntactic condition α could be any valid context-free grammar fragment.[src] More formally, a syntactic predicate is a form of production intersection, used in parser specifications or in formal grammars.[src] In this sense, the term predicate has the meaning of a mathematical indicator function.[src] If p 1 and p 2, are production rules, the language generated by both p 1 and p 2 is their set intersection.[src] As typically defined or implemented, syntactic predicates implicitly order the productions so that predicated productions specified earlier have higher precedence than predicated productions specified later within the same decision.[src] This conveys an ability to disambiguate ambiguous productions because the programmer can simply specify which production should match.…[src]

A syntactic predicate specifies the syntactic validity of applying a production in a formal grammar and is analogous to a semantic predicate that specifies the semantic validity of applying a production.[src] It is a simple and effective means of dramatically improving the recognition strength of an LL parser by providing arbitrary lookahead.[src] In their original implementation, syntactic predicates had the form “( α )?” and could only appear on the left edge of a production.[src] The required syntactic condition α could be any valid context-free grammar fragment.[src] More formally, a syntactic predicate is a form of production intersection, used in parser specifications or in formal grammars.[src] In this sense, the term predicate has the meaning of a mathematical indicator function.[src] If p 1 and p 2, are production rules, the language generated by both p 1 and p 2 is their set intersection.[src] As typically defined or implemented, syntactic predicates implicitly order the productions so that predicated productions specified earlier have higher precedence than predicated productions specified later within the same decision.[src] This conveys an ability to disambiguate ambiguous productions because the programmer can simply specify which production should match.[src] Parsing expression grammars (PEGs), invented by Bryan Ford, extend these simple predicates by allowing "not predicates" and permitting a predicate to appear anywhere within a production.[src] Moreover, Ford invented packrat parsing to handle these grammars in linear time by employing memoization, at the cost of heap space.[src] It is possible to support linear-time parsing of predicates as general as those allowed by PEGs, but reduce the memory cost associated with memoization by avoiding backtracking where some more efficient implementation of lookahead suffices.[src] This approach is implemented by ANTLR version 3, which uses Deterministic finite automata for lookahead; this may require testing a predicate in order to choose between transitions of the DFA (called "pred-LL(*)" parsing).[src] ==Overview== ===Terminology=== The term syntactic predicate was coined by Parr & Quong and differentiates this form of predicate from semantic predicates (also discussed).[src] Syntactic predicates have been called multi-step matching, parse constraints, and simply predicates in various literature.[src] (See References section below.) This article uses the term syntactic predicate throughout for consistency and to distinguish them from semantic predicates.[src] ===Formal closure properties=== Bar-Hillel et al.[src] show that the intersection of two regular languages is also a regular language, which is to say that the regular languages are closed under intersection.[src] The intersection of a regular language and a context-free language is also closed, and it has been known at least since Hartmanis that the intersection of two context-free languages is not necessarily a context-free language (and is thus not closed).[src] This can be demonstrated easily using the canonical Type 1 language, L = \{ a^n b^n c^n : n \ge 1 \} : Let L_1 = \{ a^m b^n c^n : m,n \ge 1 \} (Type 2) Let L_2 = \{ a^n b^n c^m : m,n \ge 1 \} (Type 2) Let L_3 = L_1 \cap L_2 Given the strings , , and , it is clear that the only string that belongs to both L 1 and L 2 (that is, the only one that produces a non-empty intersection) is .[src] ===Other considerations=== In most formalisms that use syntactic predicates, the syntax of the predicate is noncommutative, which is to say that the operation of predication is ordered.[src] For instance, using the above example, consider the following pseudo-grammar, where X ::= Y PRED Z is understood to mean: "Y produces X if and only if Y also satisfies predicate Z": S ::= a X X ::= Y PRED Z Y ::= a+ BNCN Z ::= ANBN c+ BNCN ::= b [BNCN] c ANBN ::= a [ANBN] b Given the string , in the case where Y must be satisfied first (and assuming a greedy implementation), S will generate aX and X in turn will generate , thereby generating .[src] In the case where Z must be satisfied first, ANBN will fail to generate , and thus is not generated by the grammar.[src] Moreover, if either Y or Z (or both) specify any action to be taken upon reduction (as would be the case in many parsers), the order that these productions match determines the order in which those side-effects occur.[src] Formalisms that vary over time (such as adaptive grammars) may rely on these side effects.[src] ===Examples of use=== ====ANTLR==== Parr & Quong give this example of a syntactic predicate: stat: (declaration)?[src] declaration | expression ; which is intended to satisfy the following informally stated constraints of C++: If it looks like a declaration, it is; otherwise if it looks like an expression, it is; otherwise it is a syntax error.[src] In the first production of rule stat, the syntactic predicate (declaration)?[src] indicates that declaration is the syntactic context that must be present for the rest of that production to succeed.[src] We can interpret the use of (declaration)?[src] as "I am not sure if declaration will match; let me try it out and, if it does not match, I shall try the next alternative." Thus, when encountering a valid declaration, the rule declaration will be recognized twice—once as syntactic predicate and once during the actual parse to execute semantic actions.[src] Of note in the above example is the fact that any code triggered by the acceptance of the declaration production will only occur if the predicate is satisfied.[src] ====Canonical examples==== The language L = \{a^n b^n c^n | n \ge 1\} can be represented in various grammars and formalisms as follows: S ← &(A !b) a+ B !c A ← a A?[src] b B ← b B?[src] c (Note: the following example actually generates L = \{a^n b^n c^n | n \ge 0\} , but is included here because it is the example given by the inventor of conjunctive grammars.[src] ): S → AB&DC A → aA | ε B → bBc | ε C → cC | ε D → aDb | ε rule S { > a+ } rule A { a ?[src] b } rule B { b ?[src] c } ==Parsers/formalisms using some form of syntactic predicate== Although by no means an exhaustive list, the following parsers and grammar formalisms employ syntactic predicates: ANTLR (Parr & Quong) As originally implemented, syntactic predicates sit on the leftmost edge of a production such that the production to the right of the predicate is attempted if and only if the syntactic predicate first accepts the next portion of the input stream.[src] Although ordered, the predicates are checked first, with parsing of a clause continuing if and only if the predicate is satisfied, and semantic actions only occurring in non-predicates.[src] Augmented Pattern Matcher (Balmas) Balmas refers to syntactic predicates as "multi-step matching" in her paper on APM.[src] As an APM parser parses, it can bind substrings to a variable, and later check this variable against other rules, continuing to parse if and only if that substring is acceptable to further rules.[src] Parsing expression grammars (Ford) Ford's PEGs have syntactic predicates expressed as the and-predicate and the not-predicate.[src] §-Calculus (Jackson) In the §-Calculus, syntactic predicates are originally called simply predicates, but are later divided into bound and free forms, each with different input properties.[src] Raku rules Raku introduces a generalized tool for describing a grammar called rules, which are an extension of Perl 5's regular expression syntax.[src] Predicates are introduced via a lookahead mechanism called before, either with " " or " " (that is: "not before").[src] Perl 5 also has such lookahead, but it can only encapsulate Perl 5's more limited regexp features.[src] ProGrammar (NorKen Technologies) ProGrammar's GDL (Grammar Definition Language) makes use of syntactic predicates in a form called parse constraints.[src] ATTENTION NEEDED: This link is no longer valid![src] Conjunctive and Boolean Grammars (Okhotin) Conjunctive grammars, first introduced by Okhotin, introduce the explicit notion of conjunction-as-predication.[src] Later treatment of conjunctive and boolean grammars is the most thorough treatment of this formalism to date.[src] ==References== ==External links== Alexander Okhotin's Conjunctive Grammars Page Alexander Okhotin's Boolean Grammars Page The Packrat Parsing and Parsing Expression Grammars Page[src]

60 sentences · 60 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Syntactic predicate." encyclopegia.org, 2026, https://encyclopegia.org/wiki/syntactic-predicate. Accessed 29 November 2026.

Chicago

"Syntactic predicate." encyclopegia.org. Accessed November 29, 2026. https://encyclopegia.org/wiki/syntactic-predicate.

APA

encyclopegia.org. (2026). Syntactic predicate. Retrieved November 29, 2026, from https://encyclopegia.org/wiki/syntactic-predicate

Accessed November 29, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1372910378 · 0.5 · snapshot enwiki-001372910378

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.