Lably
Skip to content

Conjunctive grammar

Type of formal grammar

  • 3 min read
  • 4 chapters

Related on Lably

Through Context-free grammar, Logical conjunction and Logical disjunction

The rules of a conjunctive grammar are of the form

A→α1&…&αm

where A is a nonterminal and α1, ..., αm are strings formed of symbols in Σ and V (finite sets of terminal and nonterminal symbols respectively). Informally, such a rule asserts that every string w over Σ that satisfies each of the syntactical conditions represented by α1, ..., αm therefore satisfies the condition defined by A.

Formal definition

A conjunctive grammar G is defined by the 4-tuple G=(V,Σ,R,S) where

  1. V is a finite set; each element v∈V is called a nonterminal symbol or a variable. Each variable represents a different type of phrase or clause in the sentence. Variables are also sometimes called syntactic categories.
  2. Σ is a finite set of terminals, disjoint from V, which make up the actual content of the sentence. The set of terminals is the alphabet of the language defined by the grammar G.
  3. R is a finite set of productions, each of the form A→α1&…&αm for some A in V and αi∈(V∪Σ)∗. The members of R are called the rules or productions of the grammar.
  4. S is the start variable (or start symbol), used to represent the whole sentence (or program). It must be an element of V.

It is common to list all right-hand sides for the same left-hand side on the same line, using | (the pipe symbol) to separate them. Rules A→α1&…&αm and A→β1&…&βn can hence be written as A→α1&…&αm|β1&…&βn.

Two equivalent formal definitions of the language specified by a conjunctive grammar exist. One definition is based upon representing the grammar as a system of language equations with union, intersection and concatenation and considering its least solution. The other definition generalizes Chomsky's generative definition of the context-free grammars using rewriting of terms over conjunction and concatenation.

Definition by derivation

For any strings u,v∈(V∪Σ∪{“(”,“&”,“)”})∗, we say u directly yields v, written as u⇒v, if

  • either there is a rule A→α1&…&αm∈R such that u=u1Au2 and v=u1(α1&…&αm)u2,
  • or there exists a string w∈(V∪Σ)∗ such that u=u1(w&…&w)u2 and v=u1wu2.

For any string w∈Σ∗, we say G generates w, written as S⇒∗w, if ∃k≥1∃u1,⋯,uk∈(V∪Σ∪{“(”,“&”,“)”})∗ such that S=u1⇒u2⇒⋯⇒uk=w.

The language of a grammar G=(V,Σ,R,S) is the set of all strings it generates.

Example

The grammar G=({S,A,B,C,D},{a,b,c},R,S), with productions

S→AB&DC,
A→aA|ϵ,
B→bBc|ϵ,
C→cC|ϵ,
D→aDb|ϵ,

is conjunctive. A typical derivation is

S⇒(AB&DC)⇒(aAB&DC)⇒(aB&DC)⇒(abBc&DC)⇒(abc&DC)⇒(abc&aDbC)⇒(abc&abC)⇒(abc&abcC)⇒(abc&abc)⇒abc

It can be shown that L(G)={anbncn:n≥0}. The language is not context-free, proved by the pumping lemma for context-free languages.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication