0% found this document useful (0 votes)
9 views

Theory of Automata and Formal Languages

Uploaded by

myironmanmission
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Theory of Automata and Formal Languages

Uploaded by

myironmanmission
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Subject Name: Theory of Automata and Formal Languages

Subject Code: KCS-402

1. What are the applications of automata theory?

Automata theory has a wide range of applications across various fields in computer
science and related disciplines. Here are some key applications:

1. Compiler Design:
o Lexical Analysis: Finite automata are used to design lexical analyzers
or scanners that identify tokens in the source code.
o Syntax Analysis: Context-free grammars (CFGs) and pushdown
automata (PDAs) are utilized to parse and understand the syntax of
programming languages.
2. Formal Verification:
o Model Checking: Automata theory is used to verify the correctness of
hardware and software systems by checking if a model of the system
satisfies certain properties.
o Automated Theorem Proving: Automata and formal languages help
in verifying mathematical proofs and logical assertions automatically.
3. Natural Language Processing (NLP):
o Parsing and Syntax Analysis: CFGs are used to parse natural
language sentences, aiding in syntax analysis for NLP applications.
o Tokenization: Finite automata help in breaking down text into tokens
for further processing in NLP tasks.
4. Pattern Matching:
o Regular Expressions: Used extensively in text processing, search
algorithms, and data validation to match patterns within strings.
o String Matching Algorithms: Automata-based algorithms are
employed for efficient string searching in large texts or databases.
5. Artificial Intelligence:
o State Machines for Game AI: Finite state machines (FSMs) model
the behavior of characters in video games, controlling their actions
based on states and transitions.
o Expert Systems: Automata are used in rule-based systems for
decision-making processes.
6. Networking:
o Protocol Design and Analysis: Automata theory helps in designing
and verifying communication protocols to ensure reliable data
transmission.
o Intrusion Detection Systems: Automata-based techniques are
employed to recognize patterns of malicious activities in network
traffic.
7. Database Theory:
o Query Processing: Regular languages and automata theory contribute
to the design of query processors and optimizers in relational
databases.
o Indexing and Searching: Automata are used in indexing structures
and algorithms for efficient data retrieval.
8. Robotics and Control Systems:
o Finite State Controllers: FSMs are used to design control systems for
robots and other automated systems, dictating how they respond to
inputs.
o Reactive Systems: Automata help in the design of systems that react
to real-time inputs, such as embedded systems and industrial control
systems.

2. What does it mean if something is decidable or undecidable?

Decidability refers to the ability to determine, using an algorithm, whether a given


statement or problem can be conclusively answered (with a "yes" or "no") in a finite
amount of time.

Decidable Problems

A problem is decidable if there exists an algorithm (or equivalently, a Turing machine)


that can provide a correct yes/no answer for every input instance of the problem in a
finite amount of time. In other words, the algorithm will always halt with an answer.

Examples of Decidable Problems:

1. Membership Problem for Regular Languages: Given a string and a regular


expression (or finite automaton), determine if the string belongs to the language
defined by the regular expression.
2. Membership Problem for Context-Free Languages: Given a string and a
context-free grammar, determine if the string can be generated by the grammar.
3. Palindrome Problem: Given a string, determine if it is a palindrome (i.e., it reads
the same forward and backward).
Undecidable Problems

A problem is undecidable if there is no algorithm that can provide a correct yes/no


answer for all possible input instances of the problem. In other words, there are some
instances where the algorithm might not halt, or it may not always provide a correct
answer.

Examples of Undecidable Problems:

1. Halting Problem: Given a description of a Turing machine and an input,


determine whether the Turing machine will eventually halt (stop executing) or
will run forever. Alan Turing proved that a general algorithm to solve this
problem for all possible machine-input pairs cannot exist.
2. Post Correspondence Problem: Given two lists of strings, determine if there is a
sequence of indices that creates the same string when concatenated from both
lists. This problem has been proven to be undecidable.
3. Decision Problem: Proposed by David Hilbert, this problem asks whether there is
a general algorithm to decide the truth of any given statement in a formal
mathematical system. Alonzo Church and Alan Turing independently showed that
such a general algorithm does not exist.

Importance of Decidability

1. Theoretical Implications:
o Decidability helps in understanding the limits of computation and what
can or cannot be solved using algorithms. It defines the boundary between
solvable and unsolvable problems within computer science and
mathematics.

2. Practical Applications:
o Knowing whether a problem is decidable informs researchers and
practitioners whether they should seek an algorithmic solution or consider
alternative approaches, such as heuristics, approximations, or interactive
methods.

3. Algorithm Design:
o For decidable problems, researchers focus on finding efficient algorithms
to solve them. For undecidable problems, effort may be directed towards
identifying restricted versions of the problem that are decidable or
developing partial solutions.
3. What’s the difference between a DFA and an NFA? Which one do you think is
better?
DFA (Deterministic Finite NFA (Nondeterministic Finite
Feature
Automaton) Automaton)
An automaton where each state An automaton where each state can have
Definition has exactly one transition per zero, one, or multiple transitions per input
input symbol. symbol.
Transition
δ: Q × Σ → Q δ: Q × Σ → 2^Q (power set of Q)
Function
Completely deterministic; no Non-deterministic; multiple possible next
Determinism
ambiguity in transitions. states for a given input.
Easier to implement in software
Ease of More complex to implement due to non-
and hardware due to deterministic
Implementation deterministic behavior.
nature.
Equivalent to NFA in terms of Equivalent to DFA in terms of recognizing
Expressive Power
recognizing regular languages. regular languages.
May require more states than an Can be more compact (fewer states) than
State Complexity
equivalent NFA. an equivalent DFA.
Transition Exactly one transition for each Can have multiple transitions, including ε
Complexity state and input symbol. (epsilon) transitions.
Acceptance of Accepts a string if there exists a Accepts a string if there exists at least one
String unique path to an accepting state. path to an accepting state.
Can be converted to an equivalent DFA
Can be converted to an equivalent (subset construction), but may result in an
Conversion
NFA without any change. exponential increase in the number of
states.
Generally uses more memory due
Generally uses less memory due to
Memory Usage to potentially larger number of
potentially fewer states.
states.
Faster in operation since there is Potentially slower due to multiple possible
Speed of
only one possible transition at transitions needing to be explored
Operation
each step. simultaneously.
Simple tokenizers, digital circuit
Pattern matching algorithms, simulation of
Examples of design, and other applications
parallel processes, and other applications
Usage requiring guaranteed fast
where state explosion can be managed.
response.

Which One is Better?

Neither DFA nor NFA is universally "better" than the other; it depends on the specific
application and context:

 DFA is better when:


o You need a simple and straightforward implementation.
o Deterministic and fast operations are required.
o Memory usage is less of a concern than processing speed.
 NFA is better when:
o You need a more compact representation of a language.
o The application can handle non-determinism, such as in parallel processing or
pattern matching.
o You want to take advantage of simpler state diagrams for complex regular
languages.

In summary, both DFA and NFA have their own advantages and are used in different scenarios
based on the requirements of the task at hand.

4. Can you explain what regular expressions are? Why are they important in the
context of automata and formal languages?

Regular expressions are sequences of characters that define search patterns, primarily
used for pattern matching within strings. They are a concise and flexible way to identify
strings of text that match a specific pattern or set of criteria. Regular expressions use a
combination of literal characters and special symbols to form these patterns.

Key Components of Regular Expressions:

1. Literal Characters: Simple characters that match themselves (e.g., a, b, 1).


2. Metacharacters and Operators:
o Concatenation: Juxtaposing two expressions to match a sequence (e.g., ab
matches "ab").
o Union (alternation): Using the pipe symbol | to match either of the
expressions (e.g., a|b matches "a" or "b").
o Kleene Star (*): Matches zero or more occurrences of the preceding
element (e.g., a* matches "", "a", "aa", etc.).
o Kleene Plus (+): Matches one or more occurrences of the preceding
element (e.g., a+ matches "a", "aa", "aaa", etc.).
o Optional (?): Matches zero or one occurrence of the preceding element
(e.g., a? matches "" or "a").
o Character Classes: Denoted by square brackets to match any one of
several characters (e.g., [abc] matches "a", "b", or "c").
o Ranges: Specified within character classes to match any character within a
range (e.g., [a-z] matches any lowercase letter).
o Anchors: Denote positions within the string (e.g., ^ matches the start of a
string, $ matches the end of a string).

Importance in the Context of Automata and Formal Languages


Regular expressions are significant in automata theory and formal languages for several
reasons:

1. Equivalence to Finite Automata:


o Regular expressions are equivalent in expressive power to finite automata
(both deterministic and nondeterministic). This means that for every
regular expression, there exists a finite automaton that accepts the same
language, and vice versa.
o The equivalence allows the conversion between regular expressions and
finite automata, making it easier to analyze and implement pattern
matching algorithms.

2. Language Specification:
o Regular expressions provide a formal way to describe regular languages,
which are the simplest class of languages in the Chomsky hierarchy.
o They help in specifying lexical syntax in programming languages,
defining tokens such as identifiers, keywords, and operators.

3. Pattern Matching:
o Regular expressions are widely used in text processing and search
algorithms. Tools and programming languages like grep, Perl, Python, and
JavaScript include support for regular expressions to facilitate efficient
text searching and manipulation.
o They are essential in tasks like data validation, string parsing, and text
editing, where specific patterns need to be identified or replaced.

4. Compiler Design:
o In the lexical analysis phase of compilers, regular expressions are used to
define the patterns for tokens. A lexer or scanner converts the source code
into tokens using these patterns.
o Regular expressions simplify the process of token recognition, making
compiler design more efficient.

5. Formal Verification and Model Checking:


o Regular expressions are used in formal verification methods to specify and
check properties of software and hardware systems. They help ensure that
systems behave as expected by verifying that certain patterns occur or do
not occur in the system's behavior.

6. Text Processing Tools:


o Many text editors and integrated development environments (IDEs)
support regular expressions for search-and-replace operations, making
them powerful tools for programmers and data analysts.
5. Differentiate L* and L+
L* denotes Kleene closure and is given by L* =U Li i=0
example : 0* ={Є ,0,00,000,… }
Language includes empty words also.
L+ denotes Positive closure and is given by L+= U Li
i=1 example:0+={0,00,000,… }.
6. What is Arden’s Theorem? explain with an example?

Arden's Theorem provides a method to find a regular expression solution to certain types of
linear equations involving regular expressions. It is particularly useful in the context of
automata theory for converting finite automata to regular expressions.

Theorem Statement

Let RRR and SSS be regular expressions over an alphabet. The equation X=RX+SX = RX +
SX=RX+S has a unique solution given by:

X=R∗SX = R^*SX=R∗S

Conditions

1. XXX is a regular expression representing the unknown.


2. RRR and SSS are regular expressions.
3. RRR does not contain the empty string ϵ\epsilonϵ.

Proof Sketch

1. Substitution: Substitute X=R∗SX = R^*SX=R∗S into the equation X=RX+SX =


RX + SX=RX+S.
2. Expansion: Show that R∗S=R(R∗S)+SR^*S = R(R^*S) + SR∗S=R(R∗S)+S,
which simplifies to R∗SR^*SR∗S.

Example

Consider a finite automaton with the following transition equations for state XXX:

X=aX+bX = aX + bX=aX+b

Here, R=aR = aR=a and S=bS = bS=b.

Applying Arden’s Theorem

According to Arden’s Theorem:

X=aX+b⇒X=a∗bX = aX + b \Rightarrow X = a^*bX=aX+b⇒X=a∗b


So, the regular expression for the language recognized by the automaton is a∗ba^*ba∗b.

Verification

Let's verify by interpreting the regular expression a∗ba^*ba∗b:

 a∗a^*a∗ represents zero or more occurrences of aaa.


 bbb is a terminal symbol.

Therefore, a∗ba^*ba∗b describes all strings consisting of any number of aaas followed by a
single bbb, which aligns with the original transition equation X=aX+bX = aX + bX=aX+b.

Detailed Example with Multiple States

Suppose we have the following system of equations for states XXX and YYY:

1. X=aX+bY+cX = aX + bY + cX=aX+bY+c
2. Y=dX+eY+fY = dX + eY + fY=dX+eY+f

This way, we derive the regular expressions for XXX and YYY using Arden's Theorem,
demonstrating its utility in converting systems of linear equations involving regular
expressions into their solutions.

7. Write a RE to denote a language L which accepts all the strings which begin or end
with either 00 or 11.
The r.e consists of two parts: L1=(00+11) (any no of 0’s and 1’s)
=(00+11)(0+1)*
L2=(any no of 0’s and 1’s)(00+11)
=(0+1)*(00+11) Hence r.e R=L1+L2
=[(00+11)(0+1)*] + [(0+1)* (00+11)]
8. What is Chomsky’s Classification of Languages in TOC?
Chomsky's Classification of Languages, also known as the Chomsky Hierarchy, is a containment
hierarchy of classes of formal languages. This hierarchy was introduced by Noam Chomsky in
1956 and consists of four levels, each corresponding to a different type of grammar and
automaton. Here is an overview of each level along with a diagram:

Type 0:
Recursively Enumerable Languages

 Grammar: Unrestricted Grammar


o Production rules can be of the form α→β\alpha \rightarrow \betaα→β, where α\
alphaα and β\betaβ are strings of terminals and non-terminals, and α\alphaα is not
empty.
 Automaton: Turing Machine
o The most powerful type of automaton, capable of simulating any computation.

Type 1: Context-Sensitive Languages

 Grammar: Context-Sensitive Grammar


o Production rules are of the form αAβ→αγβ\alpha A \beta \rightarrow \alpha \
gamma \betaαAβ→αγβ, where AAA is a non-terminal, and γ\gammaγ is a non-
empty string of terminals and non-terminals.
 Automaton: Linear Bounded Automaton (LBA)
o A Turing machine with a tape of limited length proportional to the input size.
Type 2: Context-Free Languages

 Grammar: Context-Free Grammar (CFG)


o Production rules are of the form A→γA \rightarrow \gammaA→γ, where AAA is
a non-terminal and γ\gammaγ is a string of terminals and/or non-terminals.
 Automaton: Pushdown Automaton (PDA)
o A finite automaton equipped with a stack.

Type 3: Regular Languages

 Grammar: Regular Grammar


o Production rules are of the form A→aBA \rightarrow aBA→aB or A→aA \
rightarrow aA→a, where AAA and BBB are non-terminals and aaa is a terminal.
 Automaton: Finite Automaton (FA)
o The simplest type of automaton, with no additional memory beyond its states.

9. Describe various Normal Forms and include their practical uses.

Normal forms are standardized formats for grammars that simplify analysis and
manipulation. The most commonly used normal forms in the Theory of Automata and
Formal Languages are Chomsky Normal Form (CNF) and Greibach Normal Form
(GNF).

Chomsky Normal Form (CNF)

A context-free grammar (CFG) is in Chomsky Normal Form if all production rules are in
one of the following forms:

1. A→BCA \rightarrow BCA→BC where A,B,A, B,A,B, and CCC are non-terminal
symbols and neither BBB nor CCC is the start symbol.
2. A→aA \rightarrow aA→a where AAA is a non-terminal and aaa is a terminal
symbol.
3. S→ϵS \rightarrow \epsilonS→ϵ if the start symbol SSS can produce the empty
string.

Greibach Normal Form (GNF)

A context-free grammar (CFG) is in Greibach Normal Form if all production rules are in
the form:

1. A→aαA \rightarrow a\alphaA→aα where AAA is a non-terminal, aaa is a


terminal symbol, and α\alphaα is a string of non-terminal symbols (possibly
empty).
Applications

1. Parsing Algorithms:
o CNF: Used in the CYK (Cocke-Younger-Kasami) parsing algorithm,
which requires the input grammar to be in CNF to efficiently determine
whether a string belongs to a given language.
o GNF: Useful in top-down parsing algorithms, as it ensures that each
production starts with a terminal, making the grammar easier to handle in
recursive descent parsers.

2. Theoretical Analysis:
o Normal forms simplify proofs in formal language theory, such as showing
that certain classes of languages are closed under specific operations.
o They help in demonstrating properties of languages, such as decidability
and equivalence.

3. Compiler Design:
o Normal forms facilitate syntax analysis in compilers by providing a
standardized way to define the syntax rules of programming languages.
o They help in optimizing parsing strategies and improving the efficiency of
syntax checkers.

4. Automata Conversion:
o Converting grammars to normal forms is a crucial step in the process of
transforming context-free grammars to equivalent automata, such as
converting CFGs to pushdown automata (PDAs).

10. What are the applications of pumping lemma?


Pumping lemma is used to check if a language is regular or not.

(i) Assume that the language(L) is regular.


(ii) Select a constant ‘n’.
(iii) Select a string(z) in L, such that |z|>n.
(iv) Split the word z into u,v and w such that |uv|<=n and |v|>=1.
(v) You achieve a contradiction to pumping lemma that there exists an ‘i’
Such that uviw is not in L.Then L is not a regular language.
11. What is :(a) derivation (b)derivation/parse tree (c) subtree
(a) Let G=(V,T,P,S) be the context free grammar. If
A->β is a production of P and α and ɶ are any strings
in (VUT)* then α A ɶ => αβɶ.
G
(b) A tree is a parse \ derivation tree for G if:
(i) Every vertex has a label which is a symbol of VU TU{Є}.
(j) The label of the root is S.
(k) If a vertex is interior and has a label A, then A must be in V.
(l) If n has a label A and vertices n1,n2,….. nk are the sons of the
vertex n in order from left with labels X1,X2,………..Xk
respectively then A→ X1X2…..Xk must be in P. (v) If vertex n
has label Є ,then n is a leaf and is the only son of its father.
(c ) A subtree of a derivation tree is a particular vertex of the tree
together with all its descendants ,the edges connecting them and their
labels.The label of the root may not be the start symbol of the
grammar.

12. If S->aSb | aAb , A->bAa , A >ba .Find out the CFL


soln. S->aAb=>abab
S->aSb=>a aAb
b =>a a ba b b(sub S->aAb) S->aSb =>a aSb b =>a a aAb b b=>a a a ba b bb
Thus L={anbmambn, where n,m>=1}
13. What is a ambiguous grammar?
A grammar is said to be ambiguous if it has more than one derivation trees for a sentence
or in other words if it has more than one leftmost derivation or more than one
rightmost derivation.
14. What are the components of PDA ?
The PDA usually consists of four components: A control unit. A Read Unit. An input
tape.
A Memory unit.
15. Differentiate PDA and TM.
PDA TM
PDA uses a stack for storage TM uses a tape that is infinite
The language accepted by PDA is CFL. Tm recognizes recursively enumerable
languages
16. Define the pushdown automata for language {a nbn | n > 0}

Solution : M = where Q = { q0, q1 } and Σ = { a, b } and Γ = { A, Z } and


δ is given by : δ( q0, a, Z ) = { ( q0, AZ ) }
δ( q0, a, A) = { ( q0, AA ) }
δ( q0, b, A) = { ( q1, ∈) }
δ( q1, b, A) = { ( q1, ∈) }
δ( q1, ∈, Z) = { ( q1, ∈) }

Let us see how this automata works for aaabbb.

17. How to convert CFG to CNF.


Solution: Consider the given grammar G1:
S → ASB
A → aAS|a|ε
B → SbS|A|bb
Step 1. As start symbol S appears on the RHS, we will create a new production
rule S0->S. Therefore, the grammar will become:
S0->S
S → ASB
A → aAS|a|ε
B → SbS|A|bb
Step 2. As grammar contains null production A-> ε, its removal from the
grammar yields:
S0->S
S → ASB|SB
A → aAS|aS|a
B → SbS| A|ε|bb
Now, it creates null production B→ ε, its removal from the grammar yields:
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS| A|bb
Now, it creates unit production B->A, its removal from the grammar yields:
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Also, removal of unit production S0->S from grammar yields:
S0-> AS|ASB| SB| S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Also, removal of unit production S->S and S0->S from grammar yields:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Step 3. In production rule A->aAS |aS and B-> SbS|aAS|aS, terminals a and b
exist on RHS with non-terminates. Removing them from RHS:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|bb|XAS|XS|a
X →a
Y→b
Also, B->bb can’t be part of CNF, removing it from grammar yields:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
Step 4: In production rule S0->ASB, RHS has more than two symbols, removing
it from grammar yields:
S0-> AS|PB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Similarly, S->ASB has more than two symbols, removing it from grammar
yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
Similarly, A->XAS has more than two symbols, removing it from grammar
yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
Similarly, B->SYS has more than two symbols, removing it from grammar
yields:
S0 -> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → TS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
T → SY
Similarly, B->XAX has more than two symbols, removing it from grammar
yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → TS|VV|US|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
T → SY
U → XA
So this is the required CNF for given grammar.
18. Construct a PDA for language L = {0n1m | n >= 1, m >= 1, m > n+2}
Approach used in this PDF

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.
Step-1: On receiving 0 push it onto stack. On receiving 1, ignore it and goto next state
Step-2: On receiving 1, ignore it and goto next state
Step-3: On receiving 1, pop a 0 from top of stack and go to next state
Step-4: On receiving 1, pop a 0 from top of stack. If stack is empty, on receiving 1 ignore
it and goto next state
Step-5: On receiving 1 ignore it. If input is finished then goto last state
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
19. Draw a Turing machine to find 1’s complement of a binary number.
1’s complement of a binary number is another binary number obtained by toggling all
bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.

Approach:
1. Scanning input string from left to right
2. Converting 1’s into 0’s
3. Converting 0’s into 1’s
4. Move the head to the start when BLANK is reached.
Steps:
 Step-1. Convert all 0’s into 1’s and all 1’s into 0’s and go right if B is found go to left.
 Step-2. Then ignore 0’s and 1’s and go left & if B found go to right
 Step-3. Stop the machine.
Here, q0 shows the initial state and q1 shows the transition state and q2 shows the final state.
And 0, 1 are the variables used and R, L shows right and left.
Explanation:
 State q0 replace ‘1’ with ‘0’ and ‘0’ with ‘1’ and move to right.
 When BLANK is reached move towards left.
 Using state ‘q2’ we reach start of the string.
 When BLANK is reached move towards right and reaches the final state q2.
20. How to convert CFG to CNF. Consider the given grammar G1:
S → ASB
A → aAS|a|ε
B → SbS|A|bb
Step 1. As start symbol S appears on the RHS, we will create a new
production rule S0->S. Therefore, the grammar will become:
S0->S
S → ASB
A → aAS|a|ε
B → SbS|A|bb
Step 2. As grammar contains null production A-> ε, its removal from the
grammar yields:
S0->S
S → ASB|SB
A → aAS|aS|a
B → SbS| A|ε|bb
Now, it creates null production B→ ε, its removal from the grammar
yields:
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS| A|bb
Now, it creates unit production B->A, its removal from the grammar
yields:
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Also, removal of unit production S0->S from grammar yields:
S0-> AS|ASB| SB| S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Also, removal of unit production S->S and S0->S from grammar yields:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Step 3. In production rule A->aAS |aS and B-> SbS|aAS|aS,terminals a
and b exist on RHS with non-terminates. Removing them from RHS:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|bb|XAS|XS|a
X →a
Y→b
Also, B->bb can’t be part of CNF, removing it from grammar yields:
S0-> AS|ASB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
Step 4: In production rule S0->ASB, RHS has more than two symbols,
removing it from grammar yields:
S0-> AS|PB| SB
S → AS|ASB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Similarly, S->ASB has more than two symbols, removing it from grammar
yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → XAS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
Similarly, A->XAS has more than two symbols, removing it from
grammar yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → SYS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
Similarly, B->SYS has more than two symbols, removing it from grammar
yields:
S0 -> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → TS|VV|XAS|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
T → SY
Similarly, B->XAX has more than two symbols, removing it from
grammar yields:
S0-> AS|PB| SB
S → AS|QB| SB
A → RS|XS|a
B → TS|VV|US|XS|a
X→a
Y→b
V→b
P → AS
Q → AS
R → XA
T → SY
U → XA
So this is the required CNF for given grammar.

You might also like