SlideShare a Scribd company logo
8
Most read
9
Most read
10
Most read
Grammar an
Introduction &
Types of
Grammar
-Sampath Kumar S,
AP/CSE, SECE
Grammar an Introduction
 Noam Chomsky gave a mathematical model of
grammar in 1956 which is effective for writing
computer languages.
 Grammar
A grammar G can be formally written as a 4-tuple
(N, T, S, P) where
1. N or VN is a set of Non-terminal symbols
2. T or ∑ is a set of Terminal symbols
3. S is the Start symbol, S ∈ N
4. P is Production rules for Terminals and Non-
terminals
11/21/2017
Sampath Kumar S, AP/CSE, SECE
2
Example 1:
Grammar G1 −
({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})
Here,
 S, A, and B are Non-terminal symbols;
 a and b are Terminal symbols
 S is the Start symbol, S ∈ N
 Productions, P : S → AB, A → a, B → b
11/21/20173
Sampath Kumar S, AP/CSE, SECE
Example 2:
Grammar G2 −
({S, A}, {a, b}, S,{S → aAb, aA →aaAb, A → ε } )
Here,
 S and A are Non-terminal symbols.
 a and b are Terminal symbols.
 ε is an empty string.
 S is the Start symbol, S ∈ N
 Production P : S → aAb, aA → aaAb, A → ε
11/21/20174
Sampath Kumar S, AP/CSE, SECE
Chomsky Classification of Grammars
According to Noam Chomosky, there are four types
of grammars
1. Type 0
2. Type 1
3. Type 2 and
4. Type 3.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
5
Chomsky Classification of Grammars
The following table shows how they differ from each
other
11/21/2017
Sampath Kumar S, AP/CSE, SECE
6
Grammar
Type
Grammar
Accepted
Language Accepted Automaton
Type 0
Unrestricted
grammar
Recursively enumerable
language
Turing Machine
Type 1
Context-sensitive
grammar
Context-sensitive
language
Linear - Bounded
automaton
Type 2
Context-free
grammar
Context-free language
Pushdown
automaton
Type 3 Regular grammar Regular language
Finite state
automaton
Illustration
11/21/2017
Sampath Kumar S, AP/CSE, SECE
7
Type - 3 Grammar
 Type-3 grammars generate regular languages.
 Type-3 grammars must have a single non-terminal on the
left-hand side and a right-hand side consisting of a single
terminal or single terminal followed by a single non-terminal.
 The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal)
and a ∈ T (Terminal)
 The rule S → ε is allowed if S does not appear on the right
side of any rule.
 Example
X → ε
X → a
X → aY
11/21/2017
Sampath Kumar S, AP/CSE, SECE
8
Type - 2 Grammar
 Type-2 grammars generate Context - Free Languages.
 The productions must be in the form A → γ
where A ∈ N (Non terminal)
and γ ∈ (T∪N)* (String of terminals and non-terminals).
 These languages generated by these grammars are be
recognized by a non-deterministic pushdown automaton.
 Example
S → X a
X → a
X → aX
X → abc
X → ε
11/21/2017
Sampath Kumar S, AP/CSE, SECE
9
Type - 1 Grammar
 Type-1 grammars generate Context- Sensitive Languages.
 The productions must be in the form α A β → α γ β
where A ∈ N (Non-terminal)
and α, β, γ ∈ (T ∪ N)* (Strings of terminals and non-terminals)
 The strings α and β may be empty, but γ must be non-empty.
 The rule S → ε is allowed if S does not appear on the right side
of any rule.
 The languages generated by these grammars are recognized
by a Linear Bounded Automaton.
 Example
AB → AbBc
A → bcA
B → b
11/21/2017
Sampath Kumar S, AP/CSE, SECE
10
Type - 0 Grammar
 Type-0 grammars generate recursively enumerable languages.
The productions have no restrictions. They are any phase
structure grammar including all formal grammars.
 They generate the languages that are recognized by a Turing
machine.
 The productions can be in the form of α → β
where α is a string of terminals and non-terminals with at least
one non-terminal and α cannot be null. β is a string of terminals
and non-terminals.
 Example
S → ACaB
Bc → acB
CB → DB
aD → Db
11/21/2017
Sampath Kumar S, AP/CSE, SECE
11
11/21/2017
Sampath Kumar S, AP/CSE, SECE
12
நன்றி
11/21/2017
Sampath Kumar S, AP/CSE, SECE
13

More Related Content

PPT
pushdown automata
PDF
Deterministic Finite Automata (DFA)
PPTX
Theory of automata and formal language
PPTX
Alphabets , strings, languages and grammars
PPTX
Context free grammar
PPTX
Context free grammar
PPT
Lecture 3,4
pushdown automata
Deterministic Finite Automata (DFA)
Theory of automata and formal language
Alphabets , strings, languages and grammars
Context free grammar
Context free grammar
Lecture 3,4

What's hot (20)

PDF
Syntax analysis
PPTX
Simplification of cfg ppt
DOCX
8-Practice problems on operator precedence parser-24-05-2023.docx
PPT
Lesson 03
PPTX
Chomsky Normal Form
PPTX
Semantic analysis
PPTX
Stressen's matrix multiplication
PPTX
Rabin karp string matching algorithm
PPTX
2.8 normal forms gnf & problems
PPTX
Regular expression to NFA (Nondeterministic Finite Automata)
PPTX
Turing machine
PPT
Turing Machine
PPT
Regular Languages
PPTX
Regular expressions
PPTX
Compiler design syntax analysis
PPTX
Regular expressions
PPT
Lecture 7
PPTX
Types of grammer - TOC
PPT
NFA or Non deterministic finite automata
PPT
Theory of Automata
Syntax analysis
Simplification of cfg ppt
8-Practice problems on operator precedence parser-24-05-2023.docx
Lesson 03
Chomsky Normal Form
Semantic analysis
Stressen's matrix multiplication
Rabin karp string matching algorithm
2.8 normal forms gnf & problems
Regular expression to NFA (Nondeterministic Finite Automata)
Turing machine
Turing Machine
Regular Languages
Regular expressions
Compiler design syntax analysis
Regular expressions
Lecture 7
Types of grammer - TOC
NFA or Non deterministic finite automata
Theory of Automata
Ad

Similar to 2.1 & 2.2 grammar introduction – types of grammar (20)

PPTX
1.5 & 1.6 regular languages & regular expression
PDF
Flat unit 3
PPTX
4.7. chomskian hierarchy of languages
PDF
compiler design Ashutosh Kumar cse-1 roll-046.pdf
PPTX
Chomsky classification of Language
PPTX
Ch2 automata.pptx
PPTX
RegularLanguageProperties [Autosaved].pptx
PPTX
1. Introduction automata throry and intoduction
PPTX
1. Introduction to machine learning and AI
PDF
Chomsky hierarchy
PPT
Normal-forms-for-Context-Free-Grammars.ppt
PPTX
Types of Language in Theory of Computation
PPT
UNIT III REGULAR GRAMMAR. in automatappt
PPTX
Regular expression
PDF
Syntax Analyzer.pdf
PPTX
Automata and Language Theory-Context Free Grammars
PDF
Ch02
PPT
Cfg part i
PPT
To lec 03
PPTX
THEORYOFAUTOMATATHEORYOFAUTOMATATHEORYOFAUTOMATA.pptx
1.5 & 1.6 regular languages & regular expression
Flat unit 3
4.7. chomskian hierarchy of languages
compiler design Ashutosh Kumar cse-1 roll-046.pdf
Chomsky classification of Language
Ch2 automata.pptx
RegularLanguageProperties [Autosaved].pptx
1. Introduction automata throry and intoduction
1. Introduction to machine learning and AI
Chomsky hierarchy
Normal-forms-for-Context-Free-Grammars.ppt
Types of Language in Theory of Computation
UNIT III REGULAR GRAMMAR. in automatappt
Regular expression
Syntax Analyzer.pdf
Automata and Language Theory-Context Free Grammars
Ch02
Cfg part i
To lec 03
THEORYOFAUTOMATATHEORYOFAUTOMATATHEORYOFAUTOMATA.pptx
Ad

More from Sampath Kumar S (20)

PPTX
5.2 primitive recursive functions
PPTX
4.6 halting problem
PPTX
4.3 techniques for turing machines construction
PPTX
4.2 variantsof turing machines (types of tm)
PPTX
4.1 turing machines
PPTX
3.6 & 7. pumping lemma for cfl & problems based on pl
PPTX
3.5 equivalence of pushdown automata and cfl
PPTX
3.4 deterministic pda
PPTX
3.1,2,3 pushdown automata definition, moves & id
PPTX
2.7 normal forms cnf & problems
PPTX
2.5 ambiguity in context free grammars
PPTX
2.4 derivations and languages
PPTX
2.3 context free grammars and languages
PPTX
1.10. pumping lemma for regular sets
PPTX
1.9. minimization of dfa
PPTX
1.8. equivalence of finite automaton and regular expressions
PPTX
1.7. eqivalence of nfa and dfa
PPTX
1.4. finite automaton with ε moves
PPTX
1.3.2 non deterministic finite automaton
PPTX
1.3.1 deterministic finite automaton
5.2 primitive recursive functions
4.6 halting problem
4.3 techniques for turing machines construction
4.2 variantsof turing machines (types of tm)
4.1 turing machines
3.6 & 7. pumping lemma for cfl & problems based on pl
3.5 equivalence of pushdown automata and cfl
3.4 deterministic pda
3.1,2,3 pushdown automata definition, moves & id
2.7 normal forms cnf & problems
2.5 ambiguity in context free grammars
2.4 derivations and languages
2.3 context free grammars and languages
1.10. pumping lemma for regular sets
1.9. minimization of dfa
1.8. equivalence of finite automaton and regular expressions
1.7. eqivalence of nfa and dfa
1.4. finite automaton with ε moves
1.3.2 non deterministic finite automaton
1.3.1 deterministic finite automaton

Recently uploaded (20)

PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Insiders guide to clinical Medicine.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharma ospi slides which help in ospi learning
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
01-Introduction-to-Information-Management.pdf
PPH.pptx obstetrics and gynecology in nursing
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
Supply Chain Operations Speaking Notes -ICLT Program
Insiders guide to clinical Medicine.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester

2.1 & 2.2 grammar introduction – types of grammar

  • 1. Grammar an Introduction & Types of Grammar -Sampath Kumar S, AP/CSE, SECE
  • 2. Grammar an Introduction  Noam Chomsky gave a mathematical model of grammar in 1956 which is effective for writing computer languages.  Grammar A grammar G can be formally written as a 4-tuple (N, T, S, P) where 1. N or VN is a set of Non-terminal symbols 2. T or ∑ is a set of Terminal symbols 3. S is the Start symbol, S ∈ N 4. P is Production rules for Terminals and Non- terminals 11/21/2017 Sampath Kumar S, AP/CSE, SECE 2
  • 3. Example 1: Grammar G1 − ({S, A, B}, {a, b}, S, {S → AB, A → a, B → b}) Here,  S, A, and B are Non-terminal symbols;  a and b are Terminal symbols  S is the Start symbol, S ∈ N  Productions, P : S → AB, A → a, B → b 11/21/20173 Sampath Kumar S, AP/CSE, SECE
  • 4. Example 2: Grammar G2 − ({S, A}, {a, b}, S,{S → aAb, aA →aaAb, A → ε } ) Here,  S and A are Non-terminal symbols.  a and b are Terminal symbols.  ε is an empty string.  S is the Start symbol, S ∈ N  Production P : S → aAb, aA → aaAb, A → ε 11/21/20174 Sampath Kumar S, AP/CSE, SECE
  • 5. Chomsky Classification of Grammars According to Noam Chomosky, there are four types of grammars 1. Type 0 2. Type 1 3. Type 2 and 4. Type 3. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 5
  • 6. Chomsky Classification of Grammars The following table shows how they differ from each other 11/21/2017 Sampath Kumar S, AP/CSE, SECE 6 Grammar Type Grammar Accepted Language Accepted Automaton Type 0 Unrestricted grammar Recursively enumerable language Turing Machine Type 1 Context-sensitive grammar Context-sensitive language Linear - Bounded automaton Type 2 Context-free grammar Context-free language Pushdown automaton Type 3 Regular grammar Regular language Finite state automaton
  • 8. Type - 3 Grammar  Type-3 grammars generate regular languages.  Type-3 grammars must have a single non-terminal on the left-hand side and a right-hand side consisting of a single terminal or single terminal followed by a single non-terminal.  The productions must be in the form X → a or X → aY where X, Y ∈ N (Non terminal) and a ∈ T (Terminal)  The rule S → ε is allowed if S does not appear on the right side of any rule.  Example X → ε X → a X → aY 11/21/2017 Sampath Kumar S, AP/CSE, SECE 8
  • 9. Type - 2 Grammar  Type-2 grammars generate Context - Free Languages.  The productions must be in the form A → γ where A ∈ N (Non terminal) and γ ∈ (T∪N)* (String of terminals and non-terminals).  These languages generated by these grammars are be recognized by a non-deterministic pushdown automaton.  Example S → X a X → a X → aX X → abc X → ε 11/21/2017 Sampath Kumar S, AP/CSE, SECE 9
  • 10. Type - 1 Grammar  Type-1 grammars generate Context- Sensitive Languages.  The productions must be in the form α A β → α γ β where A ∈ N (Non-terminal) and α, β, γ ∈ (T ∪ N)* (Strings of terminals and non-terminals)  The strings α and β may be empty, but γ must be non-empty.  The rule S → ε is allowed if S does not appear on the right side of any rule.  The languages generated by these grammars are recognized by a Linear Bounded Automaton.  Example AB → AbBc A → bcA B → b 11/21/2017 Sampath Kumar S, AP/CSE, SECE 10
  • 11. Type - 0 Grammar  Type-0 grammars generate recursively enumerable languages. The productions have no restrictions. They are any phase structure grammar including all formal grammars.  They generate the languages that are recognized by a Turing machine.  The productions can be in the form of α → β where α is a string of terminals and non-terminals with at least one non-terminal and α cannot be null. β is a string of terminals and non-terminals.  Example S → ACaB Bc → acB CB → DB aD → Db 11/21/2017 Sampath Kumar S, AP/CSE, SECE 11
  • 12. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 12

Editor's Notes

  • #2: School of EECS, WSU