SlideShare a Scribd company logo
Dr. Hussien Sharaf
Computer Science Department
dr.sharaf@from-masr.com
p.434: Regular Languages and non-
regular languages
Dr. Hussien M. Sharaf 2
Language
Defined by
Corresponding
Accepting Machine
Nondeter-minism=
Determinism
Regular expression Finite automaton, transition graph Yes
Context-free
grammar
Pushdown automaton No
Type 0 grammar Turing machine, Post machine,
Pushdown automaton
Yes
CFG
 A context-free grammar is a notation for
defining context free languages.
 It is more powerful than finite automata or
RE’s, but still cannot define all possible
languages.
 Useful for nested structures, e.g., parentheses
in programming languages.
 Basic idea is to use “variables” to stand for
sets of strings.
 These variables are defined recursively, in
terms of one another.
Dr. Hussien M. Sharaf 3
CFG formal definition
 C =(V, Σ, R, S)
 V: is a finite set of variables.
 Σ: symbols called terminals of the alphabet of the
language being defined.
 S V: a special start symbol.
 R: is a finite set of production rules of the form A→
where A V,  (V Σ)
Dr. Hussien M. Sharaf 4
CFG -1
 Define the language { anbn | n > 1}.
 Terminals = {a, b}.
 Variables = {S}.
 Start symbol = S.
 Productions ={
S → ab,
S → aSb }
Summary
S → ab
S → aSb
Dr. Hussien M. Sharaf 5
Derivation
 We derive strings in the language of a CFG by starting
with the start symbol, and repeatedly replacing some
variable A by the right side of one of its productions.
 Derivation example for “aabb”
 Using S→ aSb
generates uncompleted string that still has a non-
terminal S.
 Then using S→ ab to replace the inner S
Generates “aabb”
S aSb aabb ……[Successful derivation of aabb]
Dr. Hussien M. Sharaf 6
Balanced-parentheses
Prod1 S → (S)
Prod2 S → ()
 Derive the string ((())).
S → (S) …..[by prod1]
→ ((S)) …..[by prod1]
→ ((())) …..[by prod2]
Dr. Hussien M. Sharaf 7
Palindrome
 Describe palindrome of a’s and b’s using CGF
 1] S → aS 2] S → bS
 3] S → b 4] S → a
 Derive “baab” from the above grammar.
 S → bS [by 2]
→ baS [by 1]
→ baaS [by 1]
→ baab [by 3]
Dr. Hussien M. Sharaf 8
CFG – 2.1
 Describe anything (a+b)* using CGF
1] S → Λ 2] S → Y 3] Y→ aY
4] Y → bY 5] Y →a 6] Y→ b
 Derive “aab” from the above grammar.
 S → aY [by 3]
Y → aaY [by 3]
Y → aab [by 6]
Dr. Hussien M. Sharaf 9
CFG – 2.2
1] S → Λ 2] S → Y 3] Y→ aY
4] Y → bY 5] Y →a 6] Y→ b
 Derive “aa” from the above grammar.
 S → aY [by 3]
Y → aa [by 5]
Dr. Hussien M. Sharaf 10
Dr. Hussien M. Sharaf 11
CFG – 3
 Describe anything (a+b)* using CGF
1] S →aS 2] S → bS 3] S →Λ
 Derive “aab” from the above grammar.
 S → aS [by 1]
S → aaS [by 1]
S → aabS [by 2]
S → aabΛ [by 3] → aab
Dr. Hussien M. Sharaf 12
CFG – 4
Describe anything (a+b)*aa(a+b)* using CGF
1] S →XaaX 2] X → aX 3] X → bX
4] X →Λ
Note: rules 2, 3, 4 represents anything (a+b)*
 Derive “baabaab” from the above grammar.
 S → XaaX [by 1] X→ bXaaX [by 3]
X→ bΛaaX [by 4] X → baabX [by 3]
X → baabaX [by 2] X→ baabaaX [by 2]
X→ baabaabX [by 3] X→ baabaabΛ[by 4]
Dr. Hussien M. Sharaf 13
CFG – 5
Describe a language that has even number of a’s and even
number of b’s using CGF.
i.e. aababbab
1] S →SS 2] S →BALANCED S
3] S →S BALANCED 4] S →Λ
5] S →UNBALANCED S UNBALANCED
6] BALANCED → aa 7] BALANCED → bb
8] UNBALANCED → ab
9] UNBALANCED → ba
Dr. Hussien M. Sharaf 14
CFG – 5
 Derive “aababbab” from the above grammar.
 S → BALANCED S [by 1]
BALANCED→ aa UNBALANCED S UNBALANCED
[by 5]
UNBALANCED → aa ba S UNBALANCED [by 9]
UNBALANCED → aa ba S ab [by 8]
S → aa ba BALANCED S ab [by 3]
UNBALANCED → aa ba bb S ab [by 7]
S → aa ba bb ab [by 4]
→ aababbab
Dr. Hussien M. Sharaf 15
CFG – 6
 i.e. {Λ, ab, aaabbb,… }
 S → aSb|Λ
 Derive “aaaabbbb”
 S →aSb→aSb→aaSbb →aaaSbbb
→aaaaSbbbb →aaaabbbb
Dr. Hussien M. Sharaf 16
CFG – 7
 i.e. {Λ, ab, abbaabba,… }
 S → aSa| bSb| Λ
 Derive “abbaabba” “abba abba”
 S →aSa→abSba→abbSbba →abbaSabba→ abba abba
→ abbaabba
Dr. Hussien M. Sharaf 17
CFG – 8
 i.e. {Λ, abb, ababa,… }
 S → aSa| bSb| a| b| Λ
 Derive “ababa” “ab a ba”
 S →aSa→abSba→abSba →abSba→ ababa
 Note: an
ban
can be represented by S → aSa| b
 But an
ban
bn+1
can not be represented by CFG !
Dr. Hussien M. Sharaf 18
 i.e. {Λ, ab, abbaabba,… }
 S → aSa| bSb| Λ Derive abaaba
19
S
S
Λ
aa
S bb
S aa
Dr. Hussien M. Sharaf
CFG – 9
 Deduce CFG of addition and parse the
following expression 2+3+5
 1] S→S+S|N
 2] N→1|2|3|4|5|6|7|8|9|0
N1|N2|N3|N4|N5|N6|N7|N8|N9|N0
20
S
S+N
S
+
N
5
S
+
3
N
2
N
Can u make
another parsing
tree ?
Dr. Hussien M. Sharaf
CFG – 10
CFG – 11.1
 Deduce CFG of a addition/multiplication and
parse the following expression 2+3*5
 1] S→S+S|S*S|N
 2] N→1|2|3|4|5|6|7|8|9|0
N1|N2|N3|N4|N5|N6|N7|N8|N9|N0
21
S
S*S
S
*
N
5
S
+
3
N
2
N
Can u make
another parsing
tree ?
Dr. Hussien M. Sharaf
CFG -11.2 without ambiguity
 Deduce CFG of a addition/multiplication
and parse the following expression 2*3+5
1] S→ Term|Term + S
2] Term → N|N * Term
 3] N→1|2|3|4|5|6|7|8|9|0
N1|N2|N3|N4|N5|N6|N7|N8|N9|N0
22
S
S+N
S
+
N
5
S
*
3
N
2
N
Can u make
another parsing
tree ?
Dr. Hussien M. Sharaf
Thank you
Dr. Hussien M. Sharaf 23

More Related Content

What's hot

Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
Arab Open University and Cairo University
 
Ch02
Ch02Ch02
Ch02
Hankyo
 
5.5 permutations and combinations
5.5 permutations and combinations5.5 permutations and combinations
5.5 permutations and combinations
math123c
 
Permutation and combination
Permutation and combinationPermutation and combination
Permutation and combination
Bharath kumar Karanam
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
Animesh Chaturvedi
 
Lex analysis
Lex analysisLex analysis
Lex analysis
Suhit Kulkarni
 
Regular expression
Regular expressionRegular expression
Regular expression
Rajon
 
Intro To Formula Project
Intro To Formula ProjectIntro To Formula Project
Intro To Formula Project
Kathy Favazza
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
A. S. M. Shafi
 
Permutation & Combination
Permutation & CombinationPermutation & Combination
Permutation & Combination
Puru Agrawal
 
Probability Day 3 - Permutations and Combinations
Probability Day 3 - Permutations and CombinationsProbability Day 3 - Permutations and Combinations
Probability Day 3 - Permutations and Combinations
Kate Nowak
 
Lecture2 B
Lecture2 BLecture2 B
Lecture2 B
Hisham Elsherif
 
Discrete mathematics presentation
Discrete mathematics presentationDiscrete mathematics presentation
Discrete mathematics presentation
MdZiad
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
Jalpesh Vasa
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
Maulik Togadiya
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
奕安 陳
 
Permutation and Combination Maths
Permutation and Combination MathsPermutation and Combination Maths
Permutation and Combination Maths
Vardhan Jain
 
Alphabets , strings, languages and grammars
Alphabets , strings, languages  and grammarsAlphabets , strings, languages  and grammars
Alphabets , strings, languages and grammars
hele987
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
OCSI
 
Automata theory
Automata theoryAutomata theory
Automata theory
colleges
 

What's hot (20)

Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Ch02
Ch02Ch02
Ch02
 
5.5 permutations and combinations
5.5 permutations and combinations5.5 permutations and combinations
5.5 permutations and combinations
 
Permutation and combination
Permutation and combinationPermutation and combination
Permutation and combination
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Intro To Formula Project
Intro To Formula ProjectIntro To Formula Project
Intro To Formula Project
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Permutation & Combination
Permutation & CombinationPermutation & Combination
Permutation & Combination
 
Probability Day 3 - Permutations and Combinations
Probability Day 3 - Permutations and CombinationsProbability Day 3 - Permutations and Combinations
Probability Day 3 - Permutations and Combinations
 
Lecture2 B
Lecture2 BLecture2 B
Lecture2 B
 
Discrete mathematics presentation
Discrete mathematics presentationDiscrete mathematics presentation
Discrete mathematics presentation
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
 
Permutation and Combination Maths
Permutation and Combination MathsPermutation and Combination Maths
Permutation and Combination Maths
 
Alphabets , strings, languages and grammars
Alphabets , strings, languages  and grammarsAlphabets , strings, languages  and grammars
Alphabets , strings, languages and grammars
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Automata theory
Automata theoryAutomata theory
Automata theory
 

More from Arab Open University and Cairo University

Infos2014
Infos2014Infos2014
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
Arab Open University and Cairo University
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
Arab Open University and Cairo University
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
Arab Open University and Cairo University
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
Arab Open University and Cairo University
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
Arab Open University and Cairo University
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
Arab Open University and Cairo University
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
Arab Open University and Cairo University
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
Arab Open University and Cairo University
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
Arab Open University and Cairo University
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
Arab Open University and Cairo University
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
Arab Open University and Cairo University
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
Arab Open University and Cairo University
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
Arab Open University and Cairo University
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
Arab Open University and Cairo University
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
Arab Open University and Cairo University
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
Arab Open University and Cairo University
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
Arab Open University and Cairo University
 
CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
Arab Open University and Cairo University
 

More from Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
 
CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

Lec4

  • 1. Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. p.434: Regular Languages and non- regular languages Dr. Hussien M. Sharaf 2 Language Defined by Corresponding Accepting Machine Nondeter-minism= Determinism Regular expression Finite automaton, transition graph Yes Context-free grammar Pushdown automaton No Type 0 grammar Turing machine, Post machine, Pushdown automaton Yes
  • 3. CFG  A context-free grammar is a notation for defining context free languages.  It is more powerful than finite automata or RE’s, but still cannot define all possible languages.  Useful for nested structures, e.g., parentheses in programming languages.  Basic idea is to use “variables” to stand for sets of strings.  These variables are defined recursively, in terms of one another. Dr. Hussien M. Sharaf 3
  • 4. CFG formal definition  C =(V, Σ, R, S)  V: is a finite set of variables.  Σ: symbols called terminals of the alphabet of the language being defined.  S V: a special start symbol.  R: is a finite set of production rules of the form A→ where A V,  (V Σ) Dr. Hussien M. Sharaf 4
  • 5. CFG -1  Define the language { anbn | n > 1}.  Terminals = {a, b}.  Variables = {S}.  Start symbol = S.  Productions ={ S → ab, S → aSb } Summary S → ab S → aSb Dr. Hussien M. Sharaf 5
  • 6. Derivation  We derive strings in the language of a CFG by starting with the start symbol, and repeatedly replacing some variable A by the right side of one of its productions.  Derivation example for “aabb”  Using S→ aSb generates uncompleted string that still has a non- terminal S.  Then using S→ ab to replace the inner S Generates “aabb” S aSb aabb ……[Successful derivation of aabb] Dr. Hussien M. Sharaf 6
  • 7. Balanced-parentheses Prod1 S → (S) Prod2 S → ()  Derive the string ((())). S → (S) …..[by prod1] → ((S)) …..[by prod1] → ((())) …..[by prod2] Dr. Hussien M. Sharaf 7
  • 8. Palindrome  Describe palindrome of a’s and b’s using CGF  1] S → aS 2] S → bS  3] S → b 4] S → a  Derive “baab” from the above grammar.  S → bS [by 2] → baS [by 1] → baaS [by 1] → baab [by 3] Dr. Hussien M. Sharaf 8
  • 9. CFG – 2.1  Describe anything (a+b)* using CGF 1] S → Λ 2] S → Y 3] Y→ aY 4] Y → bY 5] Y →a 6] Y→ b  Derive “aab” from the above grammar.  S → aY [by 3] Y → aaY [by 3] Y → aab [by 6] Dr. Hussien M. Sharaf 9
  • 10. CFG – 2.2 1] S → Λ 2] S → Y 3] Y→ aY 4] Y → bY 5] Y →a 6] Y→ b  Derive “aa” from the above grammar.  S → aY [by 3] Y → aa [by 5] Dr. Hussien M. Sharaf 10
  • 11. Dr. Hussien M. Sharaf 11
  • 12. CFG – 3  Describe anything (a+b)* using CGF 1] S →aS 2] S → bS 3] S →Λ  Derive “aab” from the above grammar.  S → aS [by 1] S → aaS [by 1] S → aabS [by 2] S → aabΛ [by 3] → aab Dr. Hussien M. Sharaf 12
  • 13. CFG – 4 Describe anything (a+b)*aa(a+b)* using CGF 1] S →XaaX 2] X → aX 3] X → bX 4] X →Λ Note: rules 2, 3, 4 represents anything (a+b)*  Derive “baabaab” from the above grammar.  S → XaaX [by 1] X→ bXaaX [by 3] X→ bΛaaX [by 4] X → baabX [by 3] X → baabaX [by 2] X→ baabaaX [by 2] X→ baabaabX [by 3] X→ baabaabΛ[by 4] Dr. Hussien M. Sharaf 13
  • 14. CFG – 5 Describe a language that has even number of a’s and even number of b’s using CGF. i.e. aababbab 1] S →SS 2] S →BALANCED S 3] S →S BALANCED 4] S →Λ 5] S →UNBALANCED S UNBALANCED 6] BALANCED → aa 7] BALANCED → bb 8] UNBALANCED → ab 9] UNBALANCED → ba Dr. Hussien M. Sharaf 14
  • 15. CFG – 5  Derive “aababbab” from the above grammar.  S → BALANCED S [by 1] BALANCED→ aa UNBALANCED S UNBALANCED [by 5] UNBALANCED → aa ba S UNBALANCED [by 9] UNBALANCED → aa ba S ab [by 8] S → aa ba BALANCED S ab [by 3] UNBALANCED → aa ba bb S ab [by 7] S → aa ba bb ab [by 4] → aababbab Dr. Hussien M. Sharaf 15
  • 16. CFG – 6  i.e. {Λ, ab, aaabbb,… }  S → aSb|Λ  Derive “aaaabbbb”  S →aSb→aSb→aaSbb →aaaSbbb →aaaaSbbbb →aaaabbbb Dr. Hussien M. Sharaf 16
  • 17. CFG – 7  i.e. {Λ, ab, abbaabba,… }  S → aSa| bSb| Λ  Derive “abbaabba” “abba abba”  S →aSa→abSba→abbSbba →abbaSabba→ abba abba → abbaabba Dr. Hussien M. Sharaf 17
  • 18. CFG – 8  i.e. {Λ, abb, ababa,… }  S → aSa| bSb| a| b| Λ  Derive “ababa” “ab a ba”  S →aSa→abSba→abSba →abSba→ ababa  Note: an ban can be represented by S → aSa| b  But an ban bn+1 can not be represented by CFG ! Dr. Hussien M. Sharaf 18
  • 19.  i.e. {Λ, ab, abbaabba,… }  S → aSa| bSb| Λ Derive abaaba 19 S S Λ aa S bb S aa Dr. Hussien M. Sharaf CFG – 9
  • 20.  Deduce CFG of addition and parse the following expression 2+3+5  1] S→S+S|N  2] N→1|2|3|4|5|6|7|8|9|0 N1|N2|N3|N4|N5|N6|N7|N8|N9|N0 20 S S+N S + N 5 S + 3 N 2 N Can u make another parsing tree ? Dr. Hussien M. Sharaf CFG – 10
  • 21. CFG – 11.1  Deduce CFG of a addition/multiplication and parse the following expression 2+3*5  1] S→S+S|S*S|N  2] N→1|2|3|4|5|6|7|8|9|0 N1|N2|N3|N4|N5|N6|N7|N8|N9|N0 21 S S*S S * N 5 S + 3 N 2 N Can u make another parsing tree ? Dr. Hussien M. Sharaf
  • 22. CFG -11.2 without ambiguity  Deduce CFG of a addition/multiplication and parse the following expression 2*3+5 1] S→ Term|Term + S 2] Term → N|N * Term  3] N→1|2|3|4|5|6|7|8|9|0 N1|N2|N3|N4|N5|N6|N7|N8|N9|N0 22 S S+N S + N 5 S * 3 N 2 N Can u make another parsing tree ? Dr. Hussien M. Sharaf
  • 23. Thank you Dr. Hussien M. Sharaf 23