Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course 2 Introduction to Formal Languages and Automata Theory (part 2)

Similar presentations


Presentation on theme: "Course 2 Introduction to Formal Languages and Automata Theory (part 2)"β€” Presentation transcript:

1 Course 2 Introduction to Formal Languages and Automata Theory (part 2)
Cpt S 317: Spring 2009 Course 2 Introduction to Formal Languages and Automata Theory (part 2) The structure and the content of the lecture is based on School of EECS, WSU

2 The Chomsky Hierarchy β„’ 0 β„’ 1 β„’ 2 β„’ 3 Recursively- enumerable
Context- sensitive Context- free Regular Grammar Languages Automaton Production Rules Type-0 Recursively enumerable Turing machine 𝛼→𝛽 Type-1 Context sensitive Linear-bounded non-deterministic Turing machine 𝛼𝐴𝛽→𝛼𝛾𝛽 Type-2 Context-free Non-deterministicΒ pushdown automaton 𝐴→𝛾 Type-3 Regular Finite state automaton π΄β†’π‘Ž and π΄β†’π‘Žπ΅ β„’ 0 β„’ 1 β„’ 2 β„’ 3

3 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) Classification using the structure of their rules: Type-0 grammars: there are no restriction on the rules; Type-1 grammars/Context sensitive grammars: the rules for this type have the next form: 𝑒𝐴𝑣→𝑒𝑝𝑣, 𝑒,𝑝,π‘£βˆˆ 𝑉 𝐺 βˆ— , π‘β‰ πœ†, A∈ 𝑉 𝑁 Type-2 grammars/Context free grammars: the rules for this type are of the form: 𝐴→𝑝, π‘βˆˆ 𝑉 𝐺 βˆ— , A∈ 𝑉 𝑁 Type-3 grammars/regular grammars: the rules for this type have one of the next two forms: Cat. I rules 𝐴→𝐡𝑝 Cβ†’π‘ž or A,𝐡,𝐢∈ 𝑉 𝑁 , 𝑝,π‘žβˆˆ 𝑉 𝑇 βˆ— 𝐴→𝑝𝐡 Cat. II rules Examples: see whiteboard School of EECS, WSU

4 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) Localization lemma for context-free languages (CFL) Let 𝐺 be a context free grammar and the derivation π‘₯ 1 … π‘₯ π‘š βˆ— 𝑝, where π‘₯ 𝑖 ∈ 𝑉 𝐺 , π‘βˆˆ 𝑉 𝐺 βˆ— . Then there exists 𝑝 1 … 𝑝 π‘š ∈ 𝑉 𝐺 βˆ— such that 𝑝= 𝑝 1 … 𝑝 π‘š and π‘₯ 𝑗 βˆ— 𝑝 𝑗 . School of EECS, WSU

5 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) On the previos slide: what do you observe on the right-hand side (RHS) of the production rules? School of EECS, WSU

6 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) It is convenient to have on the RHS of a derivation only terminal or nonterminal symbols! This can be achieved without changing the type of grammar. Lemma 𝐴→𝑖 Let system 𝐺=( 𝑉 𝑁 , 𝑉 𝑇 ,𝑆,𝑃) be a context free grammar. There exists an equivalent context free grammar 𝐺 β€² with the property: if one rule contains terminals then the rule is of the form 𝐴→𝑖, A∈ 𝑉 𝑁 , 𝑖 βˆˆπ‘‰ 𝑇 . School of EECS, WSU

7 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) Lemma 𝐴→𝑖 Let system 𝐺=( 𝑉 𝑁 , 𝑉 𝑇 ,𝑆,𝑃) be a context free grammar. There exists an equivalent context free grammar 𝐺 β€² with the property: if one rule contains terminals then the rule is of the form 𝐴→𝑖, A∈ 𝑉 𝑁 , 𝑖 βˆˆπ‘‰ 𝑇 . Proof. Let 𝐺 β€² = 𝑉 𝑁 β€² , 𝑉 𝑇 β€² , 𝑆 β€² , 𝑃 β€² , where 𝑉 𝑁 βŠ† 𝑉 𝑁 β€² and 𝑃 β€² contains all β€žconvenient” rules from 𝑃. Let the following incoveninent rule: 𝑒→ 𝑣 1 𝑖 1 𝑣 2 𝑖 2 … 𝑖 𝑛 𝑣 𝑛+1 , 𝑖 π‘˜ βˆˆπ‘‰ 𝑇 , 𝑣 π‘˜ βˆˆπ‘‰ 𝑁 βˆ— We add to 𝑃 β€² the following rules: Observation: For type-0 grammars, all terminals from both sides of the rules are replaced. 𝑒→ 𝑣 1 𝑋 𝑖1 𝑣 2 𝑋 𝑖2 … 𝑋 𝑖𝑛 𝑣 𝑛+1 𝑋 π‘–π‘˜ β†’ 𝑖 π‘˜ π‘˜=1..𝑛, 𝑋 π‘–π‘˜ ∈ 𝑉 𝑁 β€² School of EECS, WSU

8 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) What is the relationship between β„’ 0 , β„’ 1 , β„’ 2 , β„’ 3 ? School of EECS, WSU

9 The Chomsky Hierarchy (cont’d)
Cpt S 317: Spring 2009 The Chomsky Hierarchy (cont’d) We have β„’ 0 βŠ‡ β„’ 1 , β„’ 2 βŠ‡ β„’ 3 . Apparently, a type-2 rule 𝐴→𝑝 is a particular case of type-1 rule 𝑒𝐴𝑣→𝑒𝑝𝑣, in which the context is empty word: 𝑒=𝑣=πœ†. This is not correct because of the restriction π‘β‰ πœ† imposed for context free grammars. School of EECS, WSU

10 Closure properties of Chomsky families
Cpt S 317: Spring 2009 Closure properties of Chomsky families Definition. Let ∘ be a binary operation on a family of languages 𝐿. We say that the family 𝐿 is closed on the operation ∘ if 𝐿 1 , 𝐿 2 ∈𝐿 then 𝐿 1 , 𝐿 2 ∈𝐿. Closure of Chomsky families under union The families β„’ 0 , β„’ 1 , β„’ 2 , β„’ 3 are closed under union. Key idea in the proof 𝐺= 𝑉 𝑁 1 βˆͺ 𝑁 2 βˆͺ𝑆 , 𝑉 𝑇 1 βˆͺ 𝑇 2 , 𝑃 1 βˆͺ 𝑃 2 βˆͺ 𝑆→ 𝑆 1 | 𝑆 2 Examples: see whiteboard School of EECS, WSU

11 Closure properties of Chomsky families
Cpt S 317: Spring 2009 Closure properties of Chomsky families Closure of Chomsky families under product The families β„’ 0 , β„’ 1 , β„’ 2 , β„’ 3 are closed under product. Key ideas in the proof For β„’ 0 , β„’ 1 , β„’ 2 𝐺= 𝑉 𝑁 1 βˆͺ 𝑁 2 βˆͺ𝑆 , 𝑉 𝑇 1 βˆͺ 𝑇 2 , 𝑃 1 βˆͺ 𝑃 2 βˆͺ 𝑆→ 𝑆 1 𝑆 2 For β„’ 3 𝐺= 𝑉 𝑁 1 βˆͺ 𝑁 2 , 𝑉 𝑇 1 βˆͺ 𝑇 2 , 𝑆 1 , 𝑃 1 β€²βˆͺ 𝑃 2 where 𝑃 1 β€² is obtained from 𝑃 1 by replacing the rules 𝐴→𝑝 with 𝐴→𝑝 𝑆 2 Examples: see whiteboard School of EECS, WSU

12 Closure properties of Chomsky families
Cpt S 317: Spring 2009 Closure properties of Chomsky families Closure of Chomsky families under Kleene closure The families β„’ 0 , β„’ 1 , β„’ 2 , β„’ 3 are closed under Kleene closure operation. Key ideas in the proof For β„’ 0 , β„’ 1 𝐺 βˆ— = 𝑉 𝑁 βˆͺ 𝑆 βˆ— ,𝑋 , 𝑉 𝑇 , 𝑆 βˆ— ,𝑃βˆͺ 𝑆 βˆ— β†’πœ† 𝑆 𝑋𝑆, 𝑋𝑖→𝑆𝑖|𝑋𝑆𝑖, π‘–βˆˆ 𝑉 𝑇 The new introduced rules are of type 1, so 𝐺 βˆ— does not modify the type of 𝐺. For β„’ 2 𝐺 βˆ— = 𝑉 𝑁 βˆͺ 𝑆 βˆ— , 𝑉 𝑇 , 𝑆 βˆ— ,𝑃βˆͺ 𝑆 βˆ— β†’ 𝑆 βˆ— 𝑆|πœ† For β„’ 3 𝐺 βˆ— = 𝑉 𝑁 βˆͺ 𝑆 βˆ— , 𝑉 𝑇 , 𝑆 βˆ— ,𝑃βˆͺ 𝑃 β€² βˆͺ 𝑆 βˆ— →𝑆|πœ† where 𝑃 β€² is obtained with category II rules, from 𝑃, namely if 𝐴→𝑝 ∈ 𝑃 then 𝐴→𝑝𝑆 ∈ 𝑃. Examples: see whiteboard School of EECS, WSU

13 Closure properties of Chomsky families
Cpt S 317: Spring 2009 Closure properties of Chomsky families Observation. Union, product and Kleene closure are called regular operations. Hence, the language families from the Chomsky classification are closed under regular operations. School of EECS, WSU


Download ppt "Course 2 Introduction to Formal Languages and Automata Theory (part 2)"

Similar presentations


Ads by Google