Cs3452 Toc Unit3
Cs3452 Toc Unit3
3 19
No e No
Topic Types of Grammar - Chomsky‘s hierarchy of languages
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Identify the hierarchy of languages. Understand
LO2 Summaraize the characteristics and limitations of grammar Understand
LO3 Observer the relation between types of grammar and automata theory Understand
Lecture notes
Type 0 Grammar:
Type 0 grammar is known as Unrestricted grammar. There is no restriction on the grammar rules
of these types of languages. These languages can be efficiently modeled by Turing machines.
For example:
bAa → aa
S→s
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
Identify the type of grammar as per Chomsky’s
hierarchy and design an appropriate automata model .
SaSBC SaBC
1 15 C210.3 Create
CBC Bab
Bbb Cbc
(AU-NOV 2022)
Design appropriate automation model for the
language defined by the grammar given below.
Sabc / aAbc
AbbA
2 15 C210.3 Create
AcBbcc
bBBb
aBaa /aaA
(AU-NOV 2021)
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 20
No e No
Topic Context-Free Grammar (CFG) and Languages
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Understand Context-Free Grammar Understand
LO2 Use parsing techniques to analyze strings according to the rules defined by Understand
a CFG,
LO3 Understand the significance of Chomsky Normal Form Understand
Lecture notes
Assessment questions to the lecture
Bloom’s
Qn
Question Answer Knowledge
No
Level
Which of the following is a characteristic of Context-Free
Grammars (CFGs)?
a) Production rules can be of the form α → βγ
1 a Understand
b) They can generate regular languages
c) They require left-linear rules
d) They cannot handle nested structures
Which of the following statements about Context-Free
Languages is true?
a) They are a proper superset of regular languages
2 a Understand
b) They can be recognized by finite automata
c) They can only generate strings of equal length
d) They cannot generate nested structures
In which phase of compiler design are Context-Free Grammars
primarily used?
a) Lexical analysis
3 b Remember
b) Syntax analysis
c) Semantic analysis
d) Code generation
Which of the following is NOT a component of a Context-Free
Grammar?
a) Terminals
4 d Remember
b) Non-terminals
c) Production rules
d) Regular expressions
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
i j k
Write CFG to accept the language defined by L={a b c |
1 2 C210.3 Understand
I,j,k,>=0 and i=j+k} (AU-NOV-2021)
What language over {0,1} does the CFG with productions
2 S00S | 11S |S00|S11|01S01 |01S10 |10S10 |10S01 |ε 13 C210.3 Apply
generate ?Justify your answer.(AU MAY-2023
Let G=(V,E,R,0 be the CFG , where V={ A,B,S}, E={ a,b} , S
is the start variable and R consist of the rules
SaB | bA
Aa | aS | BAA
Unit Lectur
3 21
No e No
Topic Derivations and Parse trees
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Derive derivations for given grammars and strings Understand
LO2 Recognize the importance of parse trees in parsing algorithms
and compiler design. Understand
LO3 Analyze and compare different parsing techniques Analyze
Lecture notes
Assessment questions to the lecture
Bloom’s
Qn
Question Answer Knowledge
No
Level
1 What is the primary purpose of a derivation tree in
formal language theory?
a) To represent the syntactic structure of a sentence
a Understand
b) To represent the semantic meaning of a sentence
c) To represent the lexical analysis of a sentence
d) To represent the runtime execution of a program
2 Which of the following best describes a parse tree?
a) A graphical representation of the syntax structure of
a string according to a given grammar
b) A runtime data structure used during program
execution a Understand
c) A linear sequence of symbols generated by a
grammar
d) A tree structure representing the execution flow of a
program
3 In a parse tree, what do the internal nodes represent? b Understand
a) Terminals in the grammar
b) Non-terminals in the grammar
c) Syntactic categories in the language
d) Lexical tokens in the input string
4 Which of the following parsing techniques directly
constructs a parse tree?
a) LL(1) parsing
c Understand
b) LR(1) parsing
c) Recursive descent parsing
d) Operator precedence parsing
5 In a derivation tree, what do the internal nodes
represent?
a) Terminals in the grammar
c Understand
b) Non-terminals in the grammar
c) Syntactic categories in the language
d) Lexical tokens in the input string
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
173-187
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 22
No e No
Topic Ambiguity in grammars and Languages
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Understand the concept of ambiguity in formal language theory Understand
and its implications for parsing.
LO2 Identify ambiguity in context-free grammars (CFGs) and regular Understand
grammars.
LO3 Construct unambiguous grammars for languages with ambiguous Apply
specifications.
Lecture notes
a context free grammar G with production rules : S -> aSb | bSa | SS | e
Left Most Derivation (LMD) and Derivation Tree : Leftmost
derivation of a string from starting symbol S is done by replacing leftmost
non-terminal symbol by RHS of corresponding production rule. For
example, the leftmost derivation of string abab from grammar G above is
done as : S => aSb => abSab => abab The symbols underlined are
replaced using production rules. Derivation Tree : It tells how a string is
derived using production rules from S and has been shown in Figure 1.
Bloom’s
Qn
Question Answer Knowledge
No
Level
1 b Remember
Which of the following best defines ambiguity in
the context of grammars and languages?
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
1 When do you say that the given grammar G is 2 C210.3 Remember
ambiguous? ( AU-DEC 2022)
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
205-215
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 23
No e No
Topic Push Down Automata (PDA): Definition – Moves - Instantaneous descriptions
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Describe the formal definition, operation of pushdown automata. Understand
LO2 Relate context free language and pushdown automata. Understand
LO3 Summarize the applications and limitations of pushdown automata. Understand
Lecture notes
Assessment questions to the lecture
Bloom’s
Qn
Question Answer Knowledge
No
Level
1 Which of the following components is NOT a part of a B Remamber
pushdown automaton (PDA)?
A) States
B) Input tape
C) Stack
D) Transition function
2 In a pushdown automaton (PDA), the transition function C Remamber
δ is defined as:
A) δ: Q × Σ × Γ → Q
B) δ: Q × Σ → Q × Γ
C) δ: Q × Σ × Γ → P(Q × Γ*)
D) δ: Q × Γ → Q × Γ*
3 What is the main purpose of the stack in a pushdown B Remamber
automaton?
A) To store input symbols
B) To store intermediate results
C) To store transition rules
D) To store the current state
4 1. Which of the following languages can be A Remamber
recognized by a pushdown automaton?
2. A) Context-free languages
3. B) Regular languages
4. C) Turing languages
5. D) Recursively enumerable languages
6.
5 1. Which of the following statements about pushdown a Remamber
automata is true?
2. A) Pushdown automata can recognize non-context-
free languages.
3. B) Pushdown automata can recognize all regular
languages.
4. C) Pushdown automata do not require a stack.
5. D) Pushdown automata are equivalent to Turing
machines.
6.
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
Design a pushdown automata that will accept strings
(a+b)* in which the number of a’s is greater than the
1 7 C210.3 Apply
number of b’s given the alphabet {a,b} (AU-MAY
2023)
Design a PDA to recognize the language , L defined
C C
2 by , L ={WCW \ W ε {0,1} and W is one’s 13 C210.3 Apply
complement of W} (AU-NAOV-2021)
What is deterministic pushdown automata (AU-MAY
3 2 C210.3 Remember
2023)
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
219-228
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 24
No e No
Topic Languages of pushdown automata
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Understand the Context-Free Languages Understand
LO2 Associate the relationship between CFLs and PDAs Understand
LO3 Infer the language Recognized by Pushdown Automata Understand
Lecture notes
Construct a PDA for language L = {0 n1m | n >= 1, m >= 1, m >
n+2}
Approach used in this PDA –
First 0’s are pushed into stack.When 0’s are finished, two 1’s are ignored.
Thereafter for every 1 as input a 0 is popped out of stack. When stack is
empty and still some 1’s are left then all of them are ignored.
Examples:
Input : 0 0 0 1 1 1 1 1 1
Result : ACCEPTED
Input : 0 0 0 0 1 1 1 1
Result : NOT ACCEPTED
Assessment questions to the lecture
Bloom’s
Qn
Question Answer Knowledge
No
Level
Which of the following languages can be accepted by a
pushdown automaton?
A) Regular languages
1 c Remember
B) Context-sensitive languages
C) Context-free languages
D) Recursively enumerable languages
The language accepted by a pushdown automaton is defined as:
B
A) The set of strings that lead to a non-final state.
2 B) The set of strings that lead to an empty stack. Remember
C) The set of strings that lead to a final state.
D) The set of strings that lead to a non-empty stack.
Which of the following acceptance criteria is commonly used for
pushdown automata?
A) Acceptance by halting on a final state.
3 b Remember
B) Acceptance by halting on an empty stack.
C) Acceptance by reaching a designated accept state.
D) Acceptance by having a non-empty stac
1. A language L is said to be accepted by a pushdown automaton
if:
2. A) There exists a string in L that leads to a non-final state. B)
4 C Remember
Every string in L leads to a non-empty stack.
3. C) Every string in L leads to an empty stack.
4. D) There exists a string in L that leads to a final state.
Which of the following statements about the languages accepted
by pushdown automata is true?
A) Pushdown automata can accept all regular languages.
B) Pushdown automata can accept all context-sensitive
5 languages. D Remember
C) Pushdown automata can accept all recursively enumerable
languages.
D) Pushdown automata can accept all recursively enumerable
languages, but not all context-sensitive languages.
Students have to prepare answers for the following questions at the end of the lecture
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
229-236
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 25
No e No
Topic Equivalence of pushdown automata and CFG -CFG to PDA
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Illustrate the equivalence between pushdown automata and context-free Understand
grammar.
LO2 Convert between CFGs and PDAs. Understand
LO3 Solve problems related to language recognition and parsing Apply
Lecture notes
S → XS | ε , A → aXb | Ab | ab
Solution
where δ −
δ(q, a, a) = {(q, ε )}
δ(q, 1, 1) = {(q, ε )}
Bloom’s
Qn
Question Answer Knowledge
No
Level
Which of the following statements about the conversion from a
CFG to a PDA is true? A) The conversion involves adding
terminals to the stack alphabet of the PDA.
B) The conversion involves adding non-terminals to the stack
1 alphabet of the PDA. a Understand
C) The conversion involves adding productions to the transition
function of the PDA.
D) The conversion involves adding productions to the set of
rules of the CFG.
2 In the conversion from a CFG to a PDA, each production of the a Understand
CFG is translated into:
A) A transition in the PDA.
B) A state in the PDA.
C) A terminal symbol in the PDA.
D) A non-terminal symbol in the PDA.
Which of the following components is added to the PDA during
the conversion from a CFG?
A) Start symbol
3 C Understand
B) Terminal symbols
C) Stack alphabet symbols
D) Transition rules
The purpose of adding ε-transitions in the conversion from a
CFG to a PDA is to:
A) Eliminate non-determinism.
4 B Understand
B) Ensure that the PDA accepts the empty string.
C) Ensure that the PDA rejects the empty string.
D) Reduce the number of states in the PDA.
In the conversion from a CFG to a PDA, the start symbol of the
CFG corresponds to:
A) The start state of the PDA.
5 B Understand
B) The initial symbol pushed onto the stack of the PDA.
C) The accept state of the PDA.
D) The reject state of the PDA.
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
237-241
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 26
No e No
Topic PDA to CFG
Bloom’s
Learning Outcome
Knowledge
(LO) At the end of this lecture, students will be able to
Level
LO1 Illustrate the equivalence between pushdown automata and context-free Understand
grammar.
LO2 Convert between CFGs and PDAs. Understand
LO3 Solve problems related to language recognition and parsing Apply
Lecture notes
Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx → XwyXyx in grammar G.
contains (x, ε), add the production rule Xwx → a Xyzb in grammar G.
Bloom’s
Qn
Question Answer Knowledge
No
Level
Which of the following statements about converting a Pushdown
Automaton (PDA) to a Context-Free Grammar (CFG) is correct?
A) Converting a PDA to a CFG is not possible.
B) Every PDA can be converted into an equivalent CFG, and
1 vice versa. b Understand
C) Only deterministic PDAs can be converted to CFGs.
D) CFGs and PDAs are unrelated formalisms and cannot be
converted into each other.
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
1. Design a pushdown automata that will accept strings 13 C210.3 Apply
(a+b)* in whichthe number of a’s is greater than
number of b’s . Convert the above PDA to its
equivalent CFG (AU-MAY 2023)
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages 242-245
Motwani R. & and
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.
Unit Lectur
3 27
No e No
Topic Deterministic Pushdown Automata
Bloom’s
Learning Outcome (LO) At the end of this lecture, students will be able to Knowledge
Level
LO1 Define Deterministic Pushdown Automata (DPDA) and distinguish them Remember
from Non-deterministic Pushdown Automata
LO2 Describe the operational model of a DPDA Understand
LO31. Differentiate between acceptance by final state and acceptance by empty Understand
stack in DPDA.
Lecture notes
Assessment questions to the lecture
Bloom’s
Qn
Question Answer Knowledge
No
Level
Which of the following statements accurately
describes Deterministic Pushdown Automata
(DPDA)?
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn
Question Marks CO Knowledge
No
Level
Reference Book
Author(s) Title of the book Page numbers
Hopcroft J.E., "Introduction to Automata Theory, Languages
Motwani R. & and
246-251
Ullman J.D., Computations", 3rd Edition, Pearson Education,
2008.