ArticleslgStudy

science

Syntactic predicate

Syntactic predicate is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Syntactic predicate rather than just read about it. In short: 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. It is a simple and effective means of dramatically improving the recognition strength of an LL parser by providing arbitrary lookahead.

Key takeaways

  • Syntactic predicate belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Syntactic predicate to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Syntactic predicate from memory before moving on to harder problems.

Reference excerpt

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. It is a simple and effective means of dramatically improving the recognition strength of an LL parser by providing arbitrary lookahead. In their original implementation, syntactic predicates had the form “( α )?” and could only appear on the left edge of a production. The required syntactic condition α could be any valid context-free grammar fragment. More formally, a syntactic predicate is a form of production intersection, used in parser specifications or in formal grammars. In this sense, the term predicate has the meaning of a mathematical indicator function. If p1 and p2, are production rules, the language generated by both p1 and p2 is their set intersection. 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. This conveys an ability to disambiguate ambiguous productions because the programmer can simply specify which production should match. 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. Moreover, Ford invented packrat parsing to handle these grammars in linear time by employing memoization, at the cost of heap space. 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. 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).

Overview

Terminology The term syntactic predicate was coined by Parr & Quong and differentiates this form of predicate from semantic predicates (also discussed). Syntactic predicates have been called multi-step matching, parse constraints, and simply predicates in various literature. (See References section below.) This article uses the term syntactic predicate throughout for consistency and to distinguish them from semantic predicates.

Formal closure properties Bar-Hillel et al. 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. 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). This can be demonstrated easily using the canonical Type 1 language, L = { a n b n c n : n ≥ 1 } {\displaystyle L=\{a^{n}b^{n}c^{n}:n\geq 1\}} :

Let L 1 = { a m b n c n : m , n ≥ 1 } {\displaystyle L_{1}=\{a^{m}b^{n}c^{n}:m,n\geq 1\}} (Type 2) Let L 2 = { a n b n c m : m , n ≥ 1 } {\displaystyle L_{2}=\{a^{n}b^{n}c^{m}:m,n\geq 1\}} (Type 2) Let L 3 = L 1 ∩ L 2 {\displaystyle L_{3}=L_{1}\cap L_{2}}

Given the strings abcc, aabbc, and aaabbbccc, it is clear that the only string that belongs to both L1 and L2 (that is, the only one that produces a non-empty intersection) is aaabbbccc.

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. 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 aaaabbbccc, in the case where Y must be satisfied first (and assuming a greedy implementation), S will generate aX and X in turn will generate aaabbbccc, thereby generating aaaabbbccc. In the case where Z must be satisfied first, ANBN will fail to generate aaaabbb, and thus aaaabbbccc is not generated by the grammar. 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. Formalisms that vary over time (such as adaptive grammars) may rely on these side effects.

Examples of use

ANTLR Parr & Quong give this example of a syntactic predicate:

which is intended to satisfy the following informally stated constraints of C++:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Syntactic predicate

Start with the simplest possible case. Write down what Syntactic predicate claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Syntactic predicate before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Syntactic predicate ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Syntactic predicate

In research
Syntactic predicate appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Syntactic predicate in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Syntactic predicate is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal languages, Parsing, so understanding it makes those chapters shorter.
In everyday life
Look for Syntactic predicate outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Syntactic predicate in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Syntactic predicate means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Syntactic predicate out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Syntactic predicate in simple terms?

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. It is a simple and effective means of dramatically improving the recognition strength of an LL…

Why does Syntactic predicate matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Syntactic predicate?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Syntactic predicate.

Tags

  • Formal languages
  • Parsing

Keep exploring