You are on page 1of 7

GREIBACH NORMAL

FORM

Submitted By:
Sayan Das(Roll No: 13000117053)
INTRODUCTION
In formal language theory, a context-free grammar is in Greibach Normal
Form (GNF) if the right-hand sides of all production rules start with
a terminal symbol, optionally followed by some variables. A non-strict form
allows one exception to this format restriction for allowing the empty
word (epsilon, ε) to be a member of the described language. The normal
form was established by Sheila Greibach and it bears her name.
More precisely, a context-free grammar is in Greibach normal form, if all
production rules are of the form:
A → aA1A2A3…..An
or
S→ε
where A is a nonterminal symbol, a is a terminal symbol, A1A2A3…An is a
(possibly empty) sequence of nonterminal symbols not including the start
symbol, S is the start symbol, and ε is the empty word.
Observe that the grammar does not have left recursions.
CONTEXT FREE GRAMMAR
Context free grammar is a formal grammar which is used to generate all
possible strings in a given formal language.
Context free grammar G can be defined by four tuples as:
G= (V, T, P, S)
Where,
G describes the grammar
T describes a finite set of terminal symbols.
V describes a finite set of non-terminal symbols
P describes a set of production rules
S is the start symbol.
In CFG, the start symbol is used to derive the string. You can derive the
string by repeatedly replacing a non-terminal by the right hand side of the
production, until all non-terminal have been replaced by terminal symbols.
In context-free grammars, all rules are one-to-one, one-to-many, or one-to-
none. These rules can be applied regardless of context. The left-hand side of
the production rule is always a non terminal symbol. This means that the
symbol does not appear in the resulting formal language.
Example:

L= {wcwR | w € (a, b)*}

Production rules:

S → aSa
S → bSb
S→c
Now check that abbcbba string can be derived from the given CFG.
S ⇒ aSa
S ⇒ abSba
S ⇒ abbSbba
S ⇒ abbcbba
By applying the production S → aSa, S → bSb recursively and finally applying the production S → c, we get the
string abbcbba.

Proper CFGs
A context-free grammar is said to be proper if it has :

 no unreachable symbols
 no unproductive symbols
 no null-productions
 no cycles
GREIBACH NORMAL FORM(GNF)
A CFG is in Greibach Normal Form if all productions are of the form
A→aX
with aT and XV*
This means, all productions start with a terminal on the PRODUCTION and have only variables
following.

Theorem:
For every CFG G with λ∉L(G) exists an equivalent grammar G' in Greibach NF.
Proof and algorithm

Firstly, we convert the given grammar into Chomsky NF:


Start with a grammar G = ( V, T, P, S)
Eliminate useless variables that cannot become terminals.
Eliminate useless variables that cannot be reached.
Eliminate λ-productions.
Eliminate unit productions.
Convert grammar to Chomsky Normal Form.
Then, we convert this grammar into an equivalent grammar in Greibach NF.
CONVERSION OF CNF TO GNF
1. Re-label all variables such that the names are A1 , A2 , ... , Am.

2. We want to order the productions, which are not terminal but contain variables. We use for this purpose the
indexing of the variables, so that
Ai→ Aj α with i<j for all i = 1,...,m and j = 2, ..., m
We perform the ordering process by substitution of the first variable on the PRODUCTION, if the production
violates the condition above (see 2 and 3).

3. We start the ordering with A1 . A1 -productions can have only a higher numbered variable as first variable on the
PRODUCTION, or a single terminal.

4. We assume now that all rules are okay up to Ak-1 . The next rule we encounter, with Ak on the production, is the
first one, which is not okay:

Ak → Al α with k>l
We resolve this problem by substituting Al . Since l<k, the Al - rules have already gone through the sorting process
and are in the proper format:
Al → Aj α with l
Now, we substitute the PRODUCTIONs of Al in the Ak -rule, and come up with:
Ak → Al α or Ak → a for some a
If l is still less than k, we substitute again. And again and again, until we get at least Ak on the PRODUCTION - all
rules up to Ak-1 are already sorted and in proper form, and the first variable on the PRODUCTION of the Ak-1 -
production must be therefore at least Ak.
CONCLUSION
The two most import ones that come to mind are the following.
Since every context-free grammar (CFG) has an equivalent CFG in GNF, we get
that every context-free language can be recognised by a real-time pushdown
automaton (PDA), that is, by a PDA for which every transition requires that an
input symbol is read.
The stack alphabet of the corresponding real-time PDA contains the
nonterminals of the CFG and its transitions can be obtained directly from the
rules of the CFG
This follows from the fact that every rule of the CFG is of the form
A→aA1…AkA→aA1…Ak for some k≥0k≥0
The PDA can then, given AA on top of the stack, replace it
with Ak…A1Ak…A1. (we here assume that the rightmost symbol in the string
of stack symbols is the top one). A transition sequence of the PDA now
corresponds to a leftmost derivation.

Another important application of Greibach Normal Form is in the proof of


Shamir’s theorem which informally speaking tells us that every context-free
language is essentially a language whose members are strings of balanced
parentheses “up to renaming of parentheses”.

You might also like