Chapter 2 automata
Chapter 2 automata
Chapter Two
Phase-Structure-Grammar (PSG)
Introduction
Definition:
A formal language is a collection of words/sentences over Σ which is formed by rules of formation.
The rules of formations are called Grammars.
Notations in defining a grammar:
Capital letters for non-terminals
Small letters for terminals
→ for “is defined as”
| for “or”
Three grammars
1. Phase-Structure-Grammar (PSG)
2. Regular Grammar (RG)
3. Context Free Grammar (CFG)
Phase-Structure-Grammar (PSG)
Definition:
PSG is a 4-tuple ( N, T, P, S ) where
1. N is finite set of non-terminals
2. T is finite set of terminals
3. P is finite set of production
Rules of the form α→ β, α Є (NUT)+ and β Є (NUT)*
4. S Є N is a Start symbol
Example:
1- Let G1 = (N, T, P, S) where
N = {A, B, S}
T = {a, b}
P is given by
S=A|B
A → aA | a
B → bB | b
2- Let G2 = (N, T, P, S) where
N = { A, B, S}
T = {a}
P is production:
S → λ | AA | BA
aS → A
AA → aA | aBB
Derivation
Let G = (N, T, P, S) be a PSG
If α1 ==> α2
α2 ==> α3 ,,,,
αn-1==> αn
then α1 ==> α2 ==> α3 ==> α4 ==> . . . . . . . . ==> αn-1 ==> αn
it is equivalent to
α1 =*=> αn (α1 generate αn in zero or more steps)
+
α1 = => αn (α1 generates αn in one or more steps)
Example:
Let G = (N, T, P, S) be a grammar with productions
S→A
A → aA | a
Find strings can be generated from G
Solution:
S => A S => A S => A
S => a S => aA S => aA
S => aa S => aaA
S => aaaA
S => aa . . . . . . aA
S => a
{a, aa, a3, a4 , , , , , , } = { an | n > 1 } - set of strings generated by the grammar
Introduction to Formal Language and Automata Page 2
MicroLink Information Technology College
d. G: S → aB | A
Solution:
L(G) = ǿ
2. Find a grammar that generates
a. L = {cn | n > 0}
b. L = { wcwR | w Є {a, b}* }
Solution:
a) L = { λ, c, c2, c3, c4 , , , , , }
Let G = ( N, T, P, S) where
N = {S}
T = {c}
P is given by:
S → cS | λ
S => λ S => cS
S => c cS
S => cc , , , , , cS
S => cc , , , , , c => cn
b) L = { c, aca, bcb, abcba , , , , , }
Let G = ( N, T, P, S) where
N = {S}
T = {a, b, c}
P is given by:
S → c | aSa | bSb
Definitions:
Let G = (N,T, P, S) be a grammar
Let α → β be a production in P
a) If β Є (NUT)+ for every α → β production then G is said to be λ-free grammar.
b) If β = λ, then α → β is called a λ-production.