Unit-3._Context_Free_Grammar[1]
Unit-3._Context_Free_Grammar[1]
Unit-3._Context_Free_Grammar[1]
A→ α X α
1 2 2
.
.
.
A→ αX α
1 n 2
REMOVAL OF LEFT RECURSION
A Grammar G (V, T, P, S) is left recursive if it has a
production in the form: A → A α |β.
The above Grammar is left recursive because the
L(G).
Then, we use the algorithm for removing useless
symbols and productions. If S is found to be
useless, then L(G) is empty otherwise L(G)
contains at least one element.
DECISION PROPERTIES OF CONTEXT FREE
LANGUAGES
Theorem: Given a context free grammar
G=(V,Σ,S,P), there exists an algorithm for
deciding whether or not L(G) is infinite.
Proof: We assume that G contains no
ε−productions, no unit-productions, and no
useless symbols.
Convert the grammar into CNF.
We draw a directed graph whose vertices are
variables in G.
If A→BC is a production, then there are directed
edges from A to B and A to C.
L is finite if and only if the directed graph has no
cycles.
DECISION PROPERTIES OF CONTEXT FREE
LANGUAGES [CYK ALGORITHM]
Theorem: Given a CFG G=(V, T, P, S) and a string w.
Whether w ∈ L(G)?
Proof: There exists an algorithm called CKY
Algorithm or Cocke-Younger-Kasami Algorithm after its
inventors. It is used to decide whether a given string belongs
to the language of grammar or not. If start variable is
member of V1n then w ∈ L(G).
EXAMPLE
For the given grammar, check the acceptance of
string w = baaba using CYK Algorithm-
S → AB / BC
A → BA / a
B → CC / b
C → AB / a