Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

Theory of Automata

By
Arjun Singh
Unit 3:
Regular and Non-Regular Grammars: Context Free Grammar(CFG)-Definition, Derivations,
Languages, Derivation Trees and Ambiguity, Regular Grammars-Right Linear and Left Linear
grammars, Conversion of FA into CFG and Regular grammar into FA, Simplification of CFG,
Normal Forms- Chomsky Normal Form(CNF), Greibach Normal Form (GNF), Chomsky
Hierarchy, Programming problems based on the properties of CFGs.

Unit 4
Push Down Automata and Properties of Context Free Languages: Nondeterministic
Pushdown Automata (NPDA)- Definition, Moves, A Language Accepted by NPDA,
Deterministic Pushdown Automata(DPDA) and Deterministic Context free Languages(DCFL),
Pushdown Automata for Context Free Languages, Context Free grammars for Pushdown
Automata, Two stack Pushdown Automata, Pumping Lemma for CFL, Closure properties of
CFL, Decision Problems of CFL, Programming problems based on the properties of CFLs.
Unit -5
Turing Machines and Recursive Function Theory : Basic Turing Machine Model, Representation of
Turing Machines, Language Acceptability of Turing Machines, Techniques for Turing Machine
Construction, Modifications of Turing Machine, Turing Machine as Computer of Integer Functions,
Universal Turing machine, Linear Bounded Automata, Church’s Thesis, Recursive and Recursively
Enumerable language, Halting Problem, Post’s Correspondance Problem, Introduction to Recursive
Function Theory.
Context Free Grammar:

CFG stand for context free grammar. Context free grammar is a


formal grammar which is used to generate all possible patterns of strings in
a given formal language.

Context free grammar g can be defined by four tuples.

G=(V,T,P,S) or (N,T,P,S)
G=G is a grammar which consist of a set of production rule. It is used to
generate the string of language.

V= set of variables or none terminal symbol.It is denoted by capital letters.

T=set of terminal symbol ,it is denoted by lower case letter


P is a production rule for terminal and
none –terminal which is used for
replacing none terminal symbol(on left
side production) in string with other
terminals or none – terminal symbol(righ
side of production)
V={A,B,C,D}
T={a,b,c,….+,-,*,/}

D=D+D
C=AS
B=b/a
A=aa
Derivation :
Derive the string “abb”for left most
derivation and right most derivation using cfg
given by
S-> AB/E
A->aB
B->Sb
Left most derivation
S
AB S->AB
aBB A->aB
aSbB B->Sb
abB S->E
abSb B->Sb
abb S->E
Right most derivation
S
AB S->AB
Asb B->sb
AEb S->E
aBb A->aB
aSbb B->Sb
abb S->E
Derivation Tree:
Derivation tree is a graphical representation for the derivation of the
given production rules . The derivation tree is also called a parse tree.

Following property of parse tree:

*The root node is always a node indicating start symbols.


*The derivation is read from left to right.
*The leaf node is always terminal nodes.
*The interior nodes are always the non-terminal nodes.
*Parse tree follows the precedence of operators

*The deepest subtree travel first . So the operator in the parent node has
less precedence , over the operation in subtree.

*
G={V,T,P,S}
where S->0B , A->1AA/£ ,
B->0AA
Example: production rule
E=E+E
E=E*E
E=a/b/c Input :a*b+c
Step 1
a*b+c
Ambiguity In Grammar :
*more than one left most derivation
* more than one right most derivation
* more than one parse tree for given i/P string
* if the grammar is not ambiguous then we call
unambiguous
* if the grammar has ambiguity then it is not
good for compiler construction.
*No method can automatically detect and remove the ambiguity.
Lets consider a grammar with production rule
E -> I
E ->E+E
E ->E*E
E ->(E )
E -> €/0/1/2/….9

G={V,T,P,S}
V={I,E}
T={+,*,(),€,0,1,2….9}
For the string 3*4+5

since two parse tree for single string so ambiguous


Left Linear grammar and Right linear grammar :
If all production are in the form of A ->Bα or A ->α where A,B € V and
α € ∑* then the grammar is called left linear grammar.

Example :
A -> Aa|Bb|b

Right Linear Grammar:

If all production are in the form of A ->αB or A ->α where A,B € V and
α € ∑* then the grammar is called Rght linear grammar.
Example:
A ->aA|bB|b
Given grammar :
S ->0A|1B|0 right linear grammar
convert to finite automata
S ->0A
S ->1B
Chomsky Normal Form(CNF):
CNF stand for Chomsky normal form. A cfg is in cnf if all production
rule satisfy one of the following
* A start symbol generating €
example : A -> €

* A non terminal generated two


example : S -> AB

* A non terminal generating a terminal


example : S -> a
Example:

G1= { S -> AB g1 satisfy the rule specified for cnf


S -> C
A->a
B -> b}

G2= { S -> aA it is does not satisfy the rule specified CNF


A ->a
B -> c}
Converting CFG into CNF:
*Eliminate start symbol from the RHS. IF the start symbol T is it right hand
side of an production create a production as:
S1 -> S

*If the grammar remove the null, unit and useless production

* Eliminate the terminal for RHS of the production if they exist with other
none terminals or terminals

Example : S -> aA can be decomposed as


S - > RA it is CNF
R -> a
*Eliminate RHS with more than two non terminals
Example :
S -> ABS

S -> RS
R -> AB

https://www.youtube.com/watch?v=XnteU4oGMuY
productions are of the form
A -> BC
or
A->a
where A,B,C € V and a € T

S - > AS|a
A -> SA|b is in cnf

S -> AS|AAS
A -> SA|aa
Thanks

You might also like