SlideShare una empresa de Scribd logo
1 de 12
WELCOME TO A
JOURNEY TO
CS419

Dr. Hussien Sharaf
Computer Science Department

dr.sharaf@from-masr.com
DEFINITION OF A LANAGUAGE “L”
∑ is the set of alphabets
*
1. Let ∑ ={x}, Then L = ∑
*
In RE, we write x
*
2. Let ∑ ={x, y}, Then L = ∑
*
In RE, we write (x+y)
3. Kleene’s star “*” means any combination of
letters of length zero or more.
Note: Please study the appendix at the end of
the lecture
Dr. Hussien M. Sharaf

2
RE RULES
Given an alphabet ∑, the set of regular expressions is
defined by the following rules.
1.

2.

For every letter in ∑, the letter written in bold is a
regular expression. Λ- lamda or ε-epsilon is a
regular expression. Λ or ε means an empty letter.
If r1 and r2 are regular expressions, then so are:
1.
2.
3.
4.

(r1)
r1 r2
r1+r2
r1* and also r2*

NOTE 1: r1+ is not a RE
NOTE 2: spaces are ignored as long as they are not included in ∑
3.

Nothing else is a regular expression.

Dr. Hussien M. Sharaf

3
RE-10.1
Example
∑ ={a, b}, What does L describe?
*
*
- L = (a+b) a(a+b)


Any string of a's and b's

Any string of a's and b's
Single a

- Give examples for words in L
{a ab aab bab abb …..}

Dr. Hussien M. Sharaf

4
RE-10.2

abbaab can be parsed in 3 ways
a bbaab
Λ a bbaab

Dr. Hussien M. Sharaf

abba a b

abb a ab
abb

a

ab

abba

a

b

5
RE-11
Example
∑ ={a, b}
- Formally describe all words with at least two a's.
1) L = b*ab*a(a + b)*
 Start with a jungle of b's (or no b's) until we find
the first a, then more b's (or no b's), then the
second a, then we finish up with anything.
- Give examples for words in L
{abbbabb aaaaa bbbabbbbabab…..}


Dr. Hussien M. Sharaf

6
RE-12
Example
∑ ={a, b}
- Formally describe all words with exactly two a's.
1) L = b*ab*ab*
- Give examples for words in L
{aab, baba, and bbbabbbab …..}
 To make the word aab, we let the first and second
b* become Λ and the last becomes b


Dr. Hussien M. Sharaf

7
RE-13.1
Example
∑ ={a, b}
- Formally describe all words with at least
one a and at least one b.
1) L = (a + b)*a(a + b)* b(a + b)*


= (anything) a(anything) b(anything)
But (a+b)*a(a+b)*b(a+b)* expresses all words except
words of the form some b’s (at least one) followed by
some a’s (at least one).
bb*aa*
Dr. Hussien M. Sharaf

8
RE-13.1
2) L =(a+b)*a(a+b)*b(a+b)* + bb*aa*
Thus: (a+b)*a(a+b)*b(a+b)* + (a+b)*b(a+b)*a(a+b)*
= (a+b)*a(a+b)*b(a+b)* + bb*aa*


Notice that it is necessary to write bb*aa*
because b*a* will admit words we do not
want, such as aaa.

Does this imply that
(a+b)*b(a+b)*a(a+b)*= bb*aa*??

False Left side includes the word aba, which
the
expression on the right side does not.
Dr. Hussien M. Sharaf

9
ASSIGNMENTS
1.
2.
3.

[One week] Solve Compilers-Sheet_0General.pdf
[One week] Solve Compilers_Sheet_1_RE.pdf
[Two weeks] Implement an email validator
using Python.
a.
b.
c.

Build a GUI using python Tkinter.
The GUI must include at least two labels, a TextBox
and a Button.
The user is given a message on a label stating
whether the email is a valid email or not.

Dr. Hussien M. Sharaf

10
DEADLINE
Thursday 28th of Feb is the deadline.
 No excuses.
 Don’t wait until last day.
 TAs can help you to the highest limit
within the next 3 days.


Dr. Hussien M. Sharaf

11
THANKS
Dr. Hussien M. Sharaf

12

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Regular expression
Regular expressionRegular expression
Regular expression
 
draft
draftdraft
draft
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Discrete mathematics presentation
Discrete mathematics presentationDiscrete mathematics presentation
Discrete mathematics presentation
 
Automata definitions
Automata definitionsAutomata definitions
Automata definitions
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
FLAT Notes
FLAT NotesFLAT Notes
FLAT Notes
 

Destacado (16)

Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
Theory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence ProblemTheory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence Problem
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
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
 
Infos2014
Infos2014Infos2014
Infos2014
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
theory of computation lecture 01
theory of computation lecture 01theory of computation lecture 01
theory of computation lecture 01
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of Computation
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Minimizing DFA
Minimizing DFAMinimizing DFA
Minimizing DFA
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 

Similar a Cs419 lec4 lexical analysis using re

Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxRaviAr5
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture mariajan8
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfdawod yimer
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01 hamzamughal39
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptashja1
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of AutomataFarooq Mian
 
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsAshu
 
1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expressionSampath Kumar S
 

Similar a Cs419 lec4 lexical analysis using re (20)

L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
regular expression
regular expressionregular expression
regular expression
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture
 
Lesson 04
Lesson 04Lesson 04
Lesson 04
 
Ch2 automata.pptx
Ch2 automata.pptxCh2 automata.pptx
Ch2 automata.pptx
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Theory of computation
Theory of computationTheory of computation
Theory of computation
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdf
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.ppt
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
13000120020_A.pptx
13000120020_A.pptx13000120020_A.pptx
13000120020_A.pptx
 
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
 
1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression
 
Regular languag regular set
Regular languag regular setRegular languag regular set
Regular languag regular set
 
Regular languag regular set
Regular languag regular setRegular languag regular set
Regular languag regular set
 

Más de Arab Open University and Cairo University

Más de Arab Open University and Cairo University (13)

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
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
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
 
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
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 

Último

Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Último (20)

Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

Cs419 lec4 lexical analysis using re

  • 1. WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. DEFINITION OF A LANAGUAGE “L” ∑ is the set of alphabets * 1. Let ∑ ={x}, Then L = ∑ * In RE, we write x * 2. Let ∑ ={x, y}, Then L = ∑ * In RE, we write (x+y) 3. Kleene’s star “*” means any combination of letters of length zero or more. Note: Please study the appendix at the end of the lecture Dr. Hussien M. Sharaf 2
  • 3. RE RULES Given an alphabet ∑, the set of regular expressions is defined by the following rules. 1. 2. For every letter in ∑, the letter written in bold is a regular expression. Λ- lamda or ε-epsilon is a regular expression. Λ or ε means an empty letter. If r1 and r2 are regular expressions, then so are: 1. 2. 3. 4. (r1) r1 r2 r1+r2 r1* and also r2* NOTE 1: r1+ is not a RE NOTE 2: spaces are ignored as long as they are not included in ∑ 3. Nothing else is a regular expression. Dr. Hussien M. Sharaf 3
  • 4. RE-10.1 Example ∑ ={a, b}, What does L describe? * * - L = (a+b) a(a+b)  Any string of a's and b's Any string of a's and b's Single a - Give examples for words in L {a ab aab bab abb …..} Dr. Hussien M. Sharaf 4
  • 5. RE-10.2 abbaab can be parsed in 3 ways a bbaab Λ a bbaab Dr. Hussien M. Sharaf abba a b abb a ab abb a ab abba a b 5
  • 6. RE-11 Example ∑ ={a, b} - Formally describe all words with at least two a's. 1) L = b*ab*a(a + b)*  Start with a jungle of b's (or no b's) until we find the first a, then more b's (or no b's), then the second a, then we finish up with anything. - Give examples for words in L {abbbabb aaaaa bbbabbbbabab…..}  Dr. Hussien M. Sharaf 6
  • 7. RE-12 Example ∑ ={a, b} - Formally describe all words with exactly two a's. 1) L = b*ab*ab* - Give examples for words in L {aab, baba, and bbbabbbab …..}  To make the word aab, we let the first and second b* become Λ and the last becomes b  Dr. Hussien M. Sharaf 7
  • 8. RE-13.1 Example ∑ ={a, b} - Formally describe all words with at least one a and at least one b. 1) L = (a + b)*a(a + b)* b(a + b)*  = (anything) a(anything) b(anything) But (a+b)*a(a+b)*b(a+b)* expresses all words except words of the form some b’s (at least one) followed by some a’s (at least one). bb*aa* Dr. Hussien M. Sharaf 8
  • 9. RE-13.1 2) L =(a+b)*a(a+b)*b(a+b)* + bb*aa* Thus: (a+b)*a(a+b)*b(a+b)* + (a+b)*b(a+b)*a(a+b)* = (a+b)*a(a+b)*b(a+b)* + bb*aa*  Notice that it is necessary to write bb*aa* because b*a* will admit words we do not want, such as aaa. Does this imply that (a+b)*b(a+b)*a(a+b)*= bb*aa*?? False Left side includes the word aba, which the expression on the right side does not. Dr. Hussien M. Sharaf 9
  • 10. ASSIGNMENTS 1. 2. 3. [One week] Solve Compilers-Sheet_0General.pdf [One week] Solve Compilers_Sheet_1_RE.pdf [Two weeks] Implement an email validator using Python. a. b. c. Build a GUI using python Tkinter. The GUI must include at least two labels, a TextBox and a Button. The user is given a message on a label stating whether the email is a valid email or not. Dr. Hussien M. Sharaf 10
  • 11. DEADLINE Thursday 28th of Feb is the deadline.  No excuses.  Don’t wait until last day.  TAs can help you to the highest limit within the next 3 days.  Dr. Hussien M. Sharaf 11