Solutions Languages Formal
Solutions Languages Formal
Authors:
Araceli Sanchis de Miguel
Agapito Ledezma Espino
Jose A. Iglesias Martínez
Beatriz García Jiménez
Juan Manuel Alonso Weber
* Several exercises are based on the ones proposed in the following books:
Enrique Alfonseca Cubero, Manuel Alfonseca Cubero, Roberto Moriyón Salomón.
Teoría de autómatas y lenguajes formales. McGraw-Hill (2007).
Manuel Alfonseca, Justo Sancho, Miguel Martínez Orga. Teoría de lenguajes,
gramáticas y autómatas. Publicaciones R.A.E.C. (1997).
Pedro Isasi, Paloma Martínez y Daniel Borrajo. Lenguajes, Gramáticas y Autómatas.
Un enfoque práctico. Addison-Wesley (1997).
Formal Languages and Automata Theory
Solution:
a)
G=({a}, {S}, S, P} where:
P={S::=a | aa | aaa}
b)
G=({a}, {S, A}, S, P} where:
P={S::=A
A::= a | aA}
c)
G=({a}, {S}, S, P} where:
P={S::= | a | aa | aaa}
d)
Solution:
a) S::= | A
A::=AA | c
S
A
AA c
AAA cA
cAA cc
cAAA ccA
ccAA ccc
b) S::= | A
A::=cAd | cd
A
cAd cd
ccAdd ccdd
cccAddd cccddd
A
AcA c
AcAcA ccA
AcAcAcA ccc
ccAcA
AcAcAcAcA
ccAcAcA ccccA
ccccAcAcA ccccccA
ccccccAcA ccccccc
ccccccAcAcA ccccccccA
ccccccccAcA ccccccccc
L(G3)={ , c, ccc, ccccc, ccccccc,…. }= {, cn} with n=1, 3, 5, ……=
={, c2n+1} with n=0,1, 2, 3, ……
Formal Languages and Automata Theory
d) S::=cA
A::=d | cA | Td
T::=Td | d
L(Gd)={cndm / n,m1}
cA
cd ccA cTd
cdd cTdd
A
cd Ad cA
L(G5)={ , cd, cdd, cddd,...... ccd, ccdd, ccddd,…. }= {, cndm} with n,m>=1
Formal Languages and Automata Theory
3. Determine the type of the following grammars into the Chomsky Hierarchy. Justify your answer.
a) G=({a,b}, {A,B,S}, S, P),
P={S::=aA, A::=bB, A::=aA, A::=a, B::=λ}
Solution:
a) Type-0.
b) Type-1.
c) Type-0.
d) Type-2.
e) Type-0.
Solution:
a) It id s Type-2 grammar.
b) L(G)={apbqcr, p=q=r=0 or p,q,r>0}.
c) word=aabcc
Formal Languages and Automata Theory
S S
A A
A A
A A
B B
a a b c c a a b c c
d)
Solution:
abc aBSc
aBaBScc
aBabcc
aBaBaBSccc
aaBbcc aBaBabccc
aaBaBbccc aBaBaaBbcccc
aaaBBbccc aBaaBaBbcccc
aaaBbbccc aBaaaBBbcccc
aaBaaBBbcccc
aaabbbccc
aaaBaBBbcccc
aaaaBBBbcccc
aaaaBBbbcccc
aaaaBbbbcccc
aaaabbbbcccc
Formal Languages and Automata Theory
6. Obtain an equivalent well formed grammar for the following one:
G = ({a,b,c,d}, {X,Y,Z,O,P,Q,A}, Z, P),
P = { Z::=Z, Q::=OP, X::=aa, Z::=aX, Y::=aa, Z::=Ya, O::=b, Z::=aaa,
P::=QO, Q::=d, P::=c, O::=PQ}
Solution:
G' = ({a}, {X,Y, Z}, Z, P'), P' = {Z::=aaa, Z::=aX, Z::=Ya, X::=aa, Y::=aa}
Solution:
Solution:
a)
G' '= ({a,b,d,z}, {A, B, C, D, E, F, X}, A, P''),
P'' = {
A::=a E::=d
A::=BC F::=b
A::=BX X::=XE
B::=a X::=XF
C::=DF X::=z
D::=z }
E::=b
Formal Languages and Automata Theory
b)
Solution:
Solution: