SlideShare a Scribd company logo
1 of 19
CSE340 - Principles of
Programming Languages
Lecture 16:
Grammars III
Javier Gonzalez-Sanchez
javiergs@asu.edu
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2
Chomsky Hierarchy
*Noam Chomsky
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Chomsky Hierarchy
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Chomsky Hierarchy
Type Name Example Use Recognizing
Automata
Parsing
Complexity
0 Recursively
Enumerated
Turing Machine Undecidable
1 Context
Sensitive
Linear Bounded
Automata
NP Complete
2 Context Free Arithmetic
Expression
x = a + b * 75
Pushdown
Automata
O(n3)
3 Regular Identifier
a110
Finite
Automata
O(n)
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Chomsky Hierarchy
Type 0 - Recursively Enumerated
structure: α → β
where α and β are any string of terminals and nonterminals
Type 1 - Context-sensitive
structure: αXβ → αγβ
where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ
must be non-empty).
Type 2 - Context-free
structure: X → γ|ε
where X is a nonterminal and γ is any string of terminals and nonterminals (may be
empty). It is discouraged to use only one nonterminal as γ.
Type 3 – Regular
structure: X → αY | α |ε
where X,Y are single nonterminals, and α is a string of terminals;
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Regular Grammar
Type 3 – Regular
structure: X → αY | α |ε
where X,Y are single nonterminals, and α is a string of terminals;
<DIGIT> → integer| | integer<DIGIT>
<Q0> → a<Q1> | b<Q0>
<Q1> → a<Q1> | b<Q0> | ε
<S> → a<S> |b<A>
<A> → c<A> | ε
<A> → ε
<A> → a
<A> → <B>a
	
  
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Regular Grammar	
  
Right Regular Grammars:
Rules of the forms
<A> → ε
<A> → a
<A> → a<B>
A,B: nonterminals and
a: terminal
The Regular Grammars are either left of right:
Left Regular Grammars:
Rules of the forms
<A> → ε
<A> → a
<A> → <B>a
A,B: nonterminals and
a: terminal
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Regular Grammar
•  Key point: The derivation process is “linear”
•  Example of Derivation process:
<S> → a<S> | b<A>
<A> → c<A> | ε
	
  
The grammar is equivalent to the regular expression a*bc*
S → aS → aaS → …
→ a…aS →a…abA →a…abcA
→ a…abccA → …
→ a…abc…c
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Context-Free Grammar
Type 2 - Context-free
structure: X → γ|ε
where X is a nonterminal and γ is any string of terminals and
nonterminals (may be empty). It is discouraged to use only one
nonterminal as γ.
<S> → <A><S> | ε
<A> → 0 <A> 1| <A>1 | 0 1
<S> → <NP><VP>
<NP> → the <N>
<VP> → <V><NP>
<V> → sings | eats
<N> → cat | song | canary	
  
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Context-Sensitive Grammar
Type 1 - Context-sensitive
structure: αXβ → αγβ
where X is a non-terminal, and α,β,γ are any string of terminals
and nonterminals, (γ must be non-empty).
<S>→ a<S><B><C>
<S> → a<B><C>
<C><B> → <H><B>
<H><B> → <H><C>
<H><C> → <B><C>
a<B> → a b
b<B> → b b
b<C> → b c
c<C> → c c
*The language generated by this grammar is {anbncn|n ≥ 1} .
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Chomsky Hierarchy
Type 0 - Recursively Enumerated
structure: α → β
where α and β are any string of terminals and nonterminals
Type 1 - Context-sensitive
structure: αXβ → αγβ
where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ
must be non-empty).
Type 2 - Context-free
structure: X → γ|ε
where X is a nonterminal and γ is any string of terminals and nonterminals (may be
empty). It is discouraged to use only one nonterminal as γ.
Type 3 – Regular
structure: X → αY | α |ε
where X,Y are single nonterminals, and α is a string of terminals;
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Exercise
G3 {
<s>à <B><A><B>
<s>à <A><B><A>
<A>à <A><B>
<A>à a<A>
<A>à ab
<B>à <B><A>
<B>à b
}
G4 {
<s>à <A><B>
<A>à a<A>
<A>à a
<B>à <B>b
<B>à b
<A><B>à <B><A>
}
G1 {
<s> à<A>
<s> à<A><A><B>
<A> àaa
<A>a à<A><B>a
<A><B> à<A><B><B>
<B>b à<A><B>b
<B> àb
}
G2 {
<s> à b<s>
<s> à a<A>
<s> à b
<A>à a<s>
<A>à b<A>
<A>à a
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Examples
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Types of Grammars
<E> → e<E>
<E> → <F>
<F> → <F>f
<F> → ε
Is this a regular grammar (X → αY | α |ε) ?
Is this a context-free grammar (X → γ|ε ) ?
Is this a context-sensitive grammar (αXβ → αγβ) ?
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Types of Grammars
if <condition> then → if “(“ <condition> “)” then
<condition> → <A> “=“ <B>
Is this a regular grammar (X → αY | α |ε) ?
Is this a context-free grammar (X → γ|ε ) ?
Is this a context-sensitive grammar (αXβ → αγβ) ?
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Types of Grammars
if “(“ <condition> “)” then → if <condition> then
<condition> → <A> “=“ <B>
Is this a regular grammar (X → αY | α |ε) ?
Is this a context-free grammar (X → γ|ε ) ?
Is this a context-sensitive grammar (αXβ → αγβ) ?
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Types of Grammars
<A> → ε
Is this a regular grammar (X → αY | α |ε) ?
Is this a context-free grammar (X → γ|ε ) ?
Is this a context-sensitive grammar (αXβ → αγβ) ?
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18
Chomsky Hierarchy
Type 0 - Recursively Enumerated
structure: α → β
where α and β are any string of terminals and nonterminals
Type 1 - Context-sensitive
structure: αXβ → αγβ
where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ
must be non-empty).
Type 2 - Context-free
structure: X → γ|ε
where X is a nonterminal and γ is any string of terminals and nonterminals (may be
empty). It is discouraged to use only one nonterminal as γ.
Type 3 – Regular
structure: X → αY | α |ε
where X,Y are single nonterminals, and α is a string of terminals;
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.

More Related Content

What's hot

1553 linear &amp; quadratic functions
1553 linear &amp; quadratic functions1553 linear &amp; quadratic functions
1553 linear &amp; quadratic functionsDr Fereidoun Dejahang
 
Herosmap_Remember me
Herosmap_Remember meHerosmap_Remember me
Herosmap_Remember mesusumu kusano
 
Asymptotes and holes 97
Asymptotes and holes 97Asymptotes and holes 97
Asymptotes and holes 97swartzje
 
Graphs of trigonometric exponential functions lecture
Graphs of trigonometric exponential functions lectureGraphs of trigonometric exponential functions lecture
Graphs of trigonometric exponential functions lectureAdnanBukhari13
 
Diffrences between derivative and diffrential
Diffrences between derivative and diffrentialDiffrences between derivative and diffrential
Diffrences between derivative and diffrentialGovind T
 

What's hot (7)

1553 linear &amp; quadratic functions
1553 linear &amp; quadratic functions1553 linear &amp; quadratic functions
1553 linear &amp; quadratic functions
 
Limit of a function
Limit of a functionLimit of a function
Limit of a function
 
Herosmap_Remember me
Herosmap_Remember meHerosmap_Remember me
Herosmap_Remember me
 
Graphing rational functions
Graphing rational functionsGraphing rational functions
Graphing rational functions
 
Asymptotes and holes 97
Asymptotes and holes 97Asymptotes and holes 97
Asymptotes and holes 97
 
Graphs of trigonometric exponential functions lecture
Graphs of trigonometric exponential functions lectureGraphs of trigonometric exponential functions lecture
Graphs of trigonometric exponential functions lecture
 
Diffrences between derivative and diffrential
Diffrences between derivative and diffrentialDiffrences between derivative and diffrential
Diffrences between derivative and diffrential
 

Viewers also liked

Tabagisme et thrombose habbal
Tabagisme et thrombose habbalTabagisme et thrombose habbal
Tabagisme et thrombose habbalsfa_angeiologie
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
Tracking Objects To Detect Feature Dependencies
Tracking Objects To Detect Feature DependenciesTracking Objects To Detect Feature Dependencies
Tracking Objects To Detect Feature Dependencieslienhard
 
The San Diego LGBT Community Center
The San Diego LGBT Community CenterThe San Diego LGBT Community Center
The San Diego LGBT Community CenterSociologistTina
 
Wolko1- Afiches de cine
Wolko1- Afiches de cineWolko1- Afiches de cine
Wolko1- Afiches de cineguest0b0bd35
 
Laserendoveineux b anastasie 1 er partie
Laserendoveineux  b anastasie   1 er partieLaserendoveineux  b anastasie   1 er partie
Laserendoveineux b anastasie 1 er partiesfa_angeiologie
 
Chapter 3 presentation
Chapter 3 presentationChapter 3 presentation
Chapter 3 presentationdphil002
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009etalcomendras
 
Paul Harris Fellow Clubs En
Paul Harris Fellow Clubs EnPaul Harris Fellow Clubs En
Paul Harris Fellow Clubs Enetalcomendras
 
악플과 악플의 재생산
악플과 악플의 재생산악플과 악플의 재생산
악플과 악플의 재생산JaeGeun Kim
 
Accomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: BostonAccomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: BostonThe Hub Milan
 
Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration PresentationEmily Reyes
 
Week14 Presentation Group-C
Week14 Presentation Group-CWeek14 Presentation Group-C
Week14 Presentation Group-Cs1160114
 
Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8andrearsya
 
Chapter 12
Chapter 12Chapter 12
Chapter 12dphil002
 
Tabagisme et thrombose habbal
Tabagisme et thrombose habbalTabagisme et thrombose habbal
Tabagisme et thrombose habbalsfa_angeiologie
 

Viewers also liked (20)

Tabagisme et thrombose habbal
Tabagisme et thrombose habbalTabagisme et thrombose habbal
Tabagisme et thrombose habbal
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Tracking Objects To Detect Feature Dependencies
Tracking Objects To Detect Feature DependenciesTracking Objects To Detect Feature Dependencies
Tracking Objects To Detect Feature Dependencies
 
The San Diego LGBT Community Center
The San Diego LGBT Community CenterThe San Diego LGBT Community Center
The San Diego LGBT Community Center
 
Wolko1- Afiches de cine
Wolko1- Afiches de cineWolko1- Afiches de cine
Wolko1- Afiches de cine
 
Diego Ernesto Leal
Diego Ernesto LealDiego Ernesto Leal
Diego Ernesto Leal
 
Laserendoveineux b anastasie 1 er partie
Laserendoveineux  b anastasie   1 er partieLaserendoveineux  b anastasie   1 er partie
Laserendoveineux b anastasie 1 er partie
 
Chapter 3 presentation
Chapter 3 presentationChapter 3 presentation
Chapter 3 presentation
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
Paul Harris Fellow Clubs En
Paul Harris Fellow Clubs EnPaul Harris Fellow Clubs En
Paul Harris Fellow Clubs En
 
open office
open officeopen office
open office
 
악플과 악플의 재생산
악플과 악플의 재생산악플과 악플의 재생산
악플과 악플의 재생산
 
Accomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: BostonAccomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: Boston
 
Demonstration Presentation
Demonstration PresentationDemonstration Presentation
Demonstration Presentation
 
Week14 Presentation Group-C
Week14 Presentation Group-CWeek14 Presentation Group-C
Week14 Presentation Group-C
 
Thehub bocconi law
Thehub   bocconi lawThehub   bocconi law
Thehub bocconi law
 
Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8Thirst Upload 800x600 1215534320518707 8
Thirst Upload 800x600 1215534320518707 8
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Tabagisme et thrombose habbal
Tabagisme et thrombose habbalTabagisme et thrombose habbal
Tabagisme et thrombose habbal
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

201506 CSE340 Lecture 16

  • 1. CSE340 - Principles of Programming Languages Lecture 16: Grammars III Javier Gonzalez-Sanchez javiergs@asu.edu BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2 Chomsky Hierarchy *Noam Chomsky
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Chomsky Hierarchy
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Chomsky Hierarchy Type Name Example Use Recognizing Automata Parsing Complexity 0 Recursively Enumerated Turing Machine Undecidable 1 Context Sensitive Linear Bounded Automata NP Complete 2 Context Free Arithmetic Expression x = a + b * 75 Pushdown Automata O(n3) 3 Regular Identifier a110 Finite Automata O(n)
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Chomsky Hierarchy Type 0 - Recursively Enumerated structure: α → β where α and β are any string of terminals and nonterminals Type 1 - Context-sensitive structure: αXβ → αγβ where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ must be non-empty). Type 2 - Context-free structure: X → γ|ε where X is a nonterminal and γ is any string of terminals and nonterminals (may be empty). It is discouraged to use only one nonterminal as γ. Type 3 – Regular structure: X → αY | α |ε where X,Y are single nonterminals, and α is a string of terminals;
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 Regular Grammar Type 3 – Regular structure: X → αY | α |ε where X,Y are single nonterminals, and α is a string of terminals; <DIGIT> → integer| | integer<DIGIT> <Q0> → a<Q1> | b<Q0> <Q1> → a<Q1> | b<Q0> | ε <S> → a<S> |b<A> <A> → c<A> | ε <A> → ε <A> → a <A> → <B>a  
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 Regular Grammar   Right Regular Grammars: Rules of the forms <A> → ε <A> → a <A> → a<B> A,B: nonterminals and a: terminal The Regular Grammars are either left of right: Left Regular Grammars: Rules of the forms <A> → ε <A> → a <A> → <B>a A,B: nonterminals and a: terminal
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Regular Grammar •  Key point: The derivation process is “linear” •  Example of Derivation process: <S> → a<S> | b<A> <A> → c<A> | ε   The grammar is equivalent to the regular expression a*bc* S → aS → aaS → … → a…aS →a…abA →a…abcA → a…abccA → … → a…abc…c
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Context-Free Grammar Type 2 - Context-free structure: X → γ|ε where X is a nonterminal and γ is any string of terminals and nonterminals (may be empty). It is discouraged to use only one nonterminal as γ. <S> → <A><S> | ε <A> → 0 <A> 1| <A>1 | 0 1 <S> → <NP><VP> <NP> → the <N> <VP> → <V><NP> <V> → sings | eats <N> → cat | song | canary  
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Context-Sensitive Grammar Type 1 - Context-sensitive structure: αXβ → αγβ where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ must be non-empty). <S>→ a<S><B><C> <S> → a<B><C> <C><B> → <H><B> <H><B> → <H><C> <H><C> → <B><C> a<B> → a b b<B> → b b b<C> → b c c<C> → c c *The language generated by this grammar is {anbncn|n ≥ 1} .
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Chomsky Hierarchy Type 0 - Recursively Enumerated structure: α → β where α and β are any string of terminals and nonterminals Type 1 - Context-sensitive structure: αXβ → αγβ where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ must be non-empty). Type 2 - Context-free structure: X → γ|ε where X is a nonterminal and γ is any string of terminals and nonterminals (may be empty). It is discouraged to use only one nonterminal as γ. Type 3 – Regular structure: X → αY | α |ε where X,Y are single nonterminals, and α is a string of terminals;
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Exercise G3 { <s>à <B><A><B> <s>à <A><B><A> <A>à <A><B> <A>à a<A> <A>à ab <B>à <B><A> <B>à b } G4 { <s>à <A><B> <A>à a<A> <A>à a <B>à <B>b <B>à b <A><B>à <B><A> } G1 { <s> à<A> <s> à<A><A><B> <A> àaa <A>a à<A><B>a <A><B> à<A><B><B> <B>b à<A><B>b <B> àb } G2 { <s> à b<s> <s> à a<A> <s> à b <A>à a<s> <A>à b<A> <A>à a }
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Examples
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14 Types of Grammars <E> → e<E> <E> → <F> <F> → <F>f <F> → ε Is this a regular grammar (X → αY | α |ε) ? Is this a context-free grammar (X → γ|ε ) ? Is this a context-sensitive grammar (αXβ → αγβ) ?
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 Types of Grammars if <condition> then → if “(“ <condition> “)” then <condition> → <A> “=“ <B> Is this a regular grammar (X → αY | α |ε) ? Is this a context-free grammar (X → γ|ε ) ? Is this a context-sensitive grammar (αXβ → αγβ) ?
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 Types of Grammars if “(“ <condition> “)” then → if <condition> then <condition> → <A> “=“ <B> Is this a regular grammar (X → αY | α |ε) ? Is this a context-free grammar (X → γ|ε ) ? Is this a context-sensitive grammar (αXβ → αγβ) ?
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 Types of Grammars <A> → ε Is this a regular grammar (X → αY | α |ε) ? Is this a context-free grammar (X → γ|ε ) ? Is this a context-sensitive grammar (αXβ → αγβ) ?
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Chomsky Hierarchy Type 0 - Recursively Enumerated structure: α → β where α and β are any string of terminals and nonterminals Type 1 - Context-sensitive structure: αXβ → αγβ where X is a non-terminal, and α,β,γ are any string of terminals and nonterminals, (γ must be non-empty). Type 2 - Context-free structure: X → γ|ε where X is a nonterminal and γ is any string of terminals and nonterminals (may be empty). It is discouraged to use only one nonterminal as γ. Type 3 – Regular structure: X → αY | α |ε where X,Y are single nonterminals, and α is a string of terminals;
  • 19. CSE340 - Principles of Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.