Course 3 Si 4
Course 3 Si 4
Formal Languages
- Basic notions -
S. Motogna - FL&CD
Regular languages
S. Motogna - FL&CD
S.Motogna - Formal Languages & Compiler Design
Finite Regular
Automata grammars
S.Motogna - Formal Languages & Compiler Design
u
d a
a n a
r c a
a
Problem: The door to the tower is closed by the Red Dragon, using a
complicated machinery. Prince Charming has managed to steal the
plans and is asking for your help. Can you help him determining all
the person names that can unlock the door
Finite Automata
• Intuitive model
a n a Σ
q
CU
S. Motogna - FL&CD
Definition: A finite automaton (FA) is a 5-tuple
M = (Q,Σ,δ,q0,F)
where:
• Q - finite set of states (|Q|<∞)
• Σ - finite alphabet (|Σ|<∞)
• δ – transition function : δ:Q×Σ→P(Q)
• q0 – initial state q0 ∊ Q
• F⊆Q – set of final states
S. Motogna - FL&CD
Remarks
1. Q∩Σ=∅
2. δ:Q×Σ→P(Q) , ε∈Σ0 - relation δ(q,ε)=p NOT allowed
3. If |δ(q,a)|≤1 => deterministic finite automaton (DFA)
4. If |δ(q,a)|>1 (more than a state obtained as result) =>
nondeterministic finite automaton (NFA)
S. Motogna - FL&CD
Configuration C=(q,x)
where:
- q state
- x unread sequence from input: x ∊ ∑*
S. Motogna - FL&CD
Relations between configurations
• ⊢ move / transition (simple, one step)
(q,ax) ⊢ (p,x) , p ∈ δ(q,a)
k
• ⊢ k move = a sequence of k simple transitions) C0 ⊢ C1 ⊢... ⊢ Ck
+
• ⊢ + move
+ k
C ⊢ Cʹ : ∃ k>0 such that C ⊢ Cʹ
*
•⊢ * move (star move)
k
C ⊢ Cʹ : ∃ k≥0 such that
* C ⊢ Cʹ
S. Motogna - FL&CD
Definition : Language accepted by FA M = (Q,Σ,δ,q0,F) is:
*
L(M)={ w ∈ Σ∗ | (q0,w) ⊢ (qf ,ε) , qf ∈F }
Remarks
1. 2 finite automata M1 and M2 are equivalent if and only if they
accept the same language
L(M1)=L(M2)
1. ε ∈ L(M) ó q0∈F (initial state is final state)
S. Motogna - FL&CD
Representing FA b
a b
1. List of all elements p q r
2. Table a
3. Graphical representation
M=(Q,Σ,δ,p,F)
M=(Q,Σ,δ,p,F)
Q = {p,q,r}
F = {r}
Σ = {a,b}
δ(p,a) = q a b
δ(q,a)=q p q r (p,aab)|-(q,ab)|-(q,b)|-(r,ε) => aab accepted
δ(q,b)=r
q q r (p,aba)|-(q,ba)|-(r,a) => aba not accepted
δ(p,b)=r
F = {r} r - -
S. Motogna - FL&CD
Remember
• Finite automaton
M = (Q,Σ,δ,q0,F)
*
L(M)={ w ∈ Σ∗ | (q0,w) ⊢ (qf ,ε) , qf ∈F }
Reg exp
Maths
Finite Regular
Automata grammars
Proof: constructive
i. G = ({S}, 𝚺, 𝞥, S) – regular grammar such that L(G) = 𝞥
Proof: constructive
L1,L2 right linear languages => ∃G1, G2 such that
G1 = (N1, 𝚺1,P1,S1) and L1 = L(G1)
G2 = (N2, 𝚺2,P2,S2) and L2 = L(G2) assume N1∩N2 = ∅
P5 = P1 U {S5 → 𝝴} U
{S5→ 𝛂1| S1→ 𝛂 1∊ P1} U
{A→ aS1| if A→ a ∊ P1}
Proof: 𝑞1 = 𝑞30 + 𝝴
=> Apply lemma 1 and lemma 2 (to follow, similar to RG) !𝑞2 = 𝑞10 + 𝑞11 + 𝑞20 + 𝑞30
<= construct a system of regular exp equations where: 𝑞3 = 𝑞21
- Indeterminants – states
- Coefficients – terminals Regular exp = union of
- Equation for A: all the possibilities that put the FA in solutions corresponding
state A
- Equation of the form: X=Xa+b => solution X=ba*
to final states
F3 = F2 U {q ∊ F1 | if q02 ∊ F2}
𝛿3(q,a) = 𝛿1(q,a), if q ∊ Q1-F1
𝛿1(q,a) U 𝛿2(q02,a) if q ∊ F1
𝛿2(q,a), if q ∊ Q2 L(M3) = L(M1)L(M2)
PROOF!!! Homework
L(M3) = L(M1)*
PROOF!!! Homework