0% found this document useful (0 votes)
15 views243 pages

ACD_Notes MID-1[1]

The document covers fundamental concepts in Automata and Compiler Design, focusing on finite automata, regular expressions, and pushdown automata. It explains the definitions of alphabets, strings, languages, and the operations on them, as well as the principles of regular expressions and their representation. Additionally, it introduces pushdown automata, highlighting their enhanced capabilities compared to finite automata and includes review questions for assessment.

Uploaded by

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

ACD_Notes MID-1[1]

The document covers fundamental concepts in Automata and Compiler Design, focusing on finite automata, regular expressions, and pushdown automata. It explains the definitions of alphabets, strings, languages, and the operations on them, as well as the principles of regular expressions and their representation. Additionally, it introduces pushdown automata, highlighting their enhanced capabilities compared to finite automata and includes review questions for assessment.

Uploaded by

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

Automata and Compiler Design

UNIT 1
1
FINITE AUTOMATA
After going through this chapter, you should be able to understand

• Alphabets, Strings and Languages


• Mathematical Induction
• Finite Automata
• Equivalence of NFA and DFA
• NFAwith e - moves

1. 1 ALPHABETS, STRINGS & LANGUAGES

Alphabet

An alphabet, denoted by L , is a finiteand nonempty set ofsymbols.

Example:
1. If L is an alphabet containing all the 26 characters used in English language, then
L is finiteand nonempty set,and L = {a, b, c, .... , z} .
2. X = { O ,1} is an alphabet.
3. Y = {I , 2 , 3 , ... } is not an alphabet becauseit is infinite.
4. z ={ } is notanalphabet because itis empty.

String

A string is a finite sequence ofsymbols from some alphabet.

Example :

" xyz " is a string over an alphabet L = {a, b, c, ... , z} . The empty string or null string is
denoted by e .
1.2 FORMALLANGUAGESANDAUTOMATA THEORY

Length of a string

The length ofa string is the number of symbols in that string. If w is a string then its length
is denoted by I w I -

Example:

1. w=abcd, then length of w is I w I= 4


2. n = 010 is a string, then In I= 3

3. e is the empty string and has length zero.

The set of strings of length K (K � 1)

Let L be an alphabet and L = {a, b} ,then all strings oflength K ( K � 1) is denoted by L x •


L ={w: w is a string of length K, K � l}
K

Example:

1. L = {a,b}, then
L 1 = {a,b},
L 2 = { aa ,. ab , ba, bb} ,
L 3 = {aaa,aab,aba,abb,baa, bab,bba,bbb}
I L 1 1 = 2 = 2 1 (Number ofstrings oflength one),
I L 2 1 = 4 = 2 2 (Number ofstrings oflengthtwo),and
l L 3 = 8 = 23 (Number ofstrings oflengththree)
j

2. S = {0,1,2} ,then S 2 = {00 ,01,02 ,11, 10,12,22,20,21} , and jS2 1= 9 = 3 2

Concatenation of strings

If w1 and w2 are two strings then concatenation of w2 with w 1 is a string and it is denoted by
w1 w2 . In other words, we can say that w1 is followed by w2 and I w1 w2 I = I w1 I + I w2 I -
Automata and Compiler Design

UNIT 2
3.2 FORMALLANGUAGESANDAUTOMATATHEORY

3.2 REGULAR EXPRESSIONS


The languages accepted by FAare regular languages and these languages are easily described
by simple expressionscalled regular expressions.We have some algebraic notations to represent
the regular expressions.

Regular expressions are means to represent certain sets ofstrings in some algebraic
manner and regular expressions describe the language accepted by FA.

If :E is an alphabet then regular expr ession(s) over thiscan be described by followingr ules.
1. Any symbol from :E,e and cl> are regular expressions.
2. If r1 and r2 are two regular expressions then union of these r epresented as r1 u r2 or
, + r2 is also a regular expression
1

3. If r, and r1 are two regular expressions then concatenation of these represented as r1 r2 is


also a regular expression.
4. The Kleeneclosure ofa regular expression r is denoted by , • is also a regular expression.
5. Ifris a regular expression then (r) is also a regular expression.
6. The regular expressions obtained by applying r ules I to 5 once or more than once are also
regularexpressions.

Examples:
(1) H '.E = {a, b}, then
(a) a is a regular expression (Usiog r ule I)
(b) b is a regular expression (Usingr ule 1)
(c) a + b isa regular expression (Usingrule2)
(d) b • is a regular expression (Usingrule4)
(e) ab is a regular expression (Usingrule3)
(l) ab + b • is a regular expression (Usiogr ule6)
(2) Fmd rcgUlar expression for the following
(a) Alanguageconsists ofallthewordsover {a,b} endinginb,
(b) A language consists ofall the words over {a, b} endingin bb-
(c) Alanguageconsists of all thewords over {a,b} starting with a and endinginb.
(d) Al anguagec.onsists ofall thewordsover {a,b} having bb as a s ubstring.
(e) Alanguage consists ofall the words over (a, b} ending in aab.
Solution : Let :t = {a,b}, and
All the words over :t = {e, a, b, aa, bb, ab, ba, aaa, ..... } = :E * or (a + b) * or (au b) •
S.62 FORMALLANGUAGESANDA\JTOMATATHEORY

REVIEW QUESTIONS

Q 1, Define context free grammar.


Ar,swer:
For Answer refer to Topic: 5.1, Page No: 5.1.
Q2.Considerthegrammar G = (V, T, P,S) havingproductions:
S ➔ aSa I bSbl e. Checkthe productions and findthe language generated.
Answer:
For Answer refer to example - I , Page No: 5.1.
Q3. Let G = ( V, T, P.S ) where V = {S , C } , T = { a , b}
P={S ➔ aCa
C -► aCalb
} S Is the start symbol
What is the language generated by this grammar?
Answer:
For Answer refer to example - 2 , Page No : 5.2.
Q4. What is the language generated by the grammar
S ➔ OAI E
A ➔ JS
Answer:
For Answer refer to example - 3, Page No : 5.2.
QS.Show that the language L = { am b" I m;, n ) is context free.
Answer:
For Answer refer to example - 4 , Page No : 5.3.
Q6. Draw a CFG to generate a language consisting of equal number of a's and b's.
Answer:
For Answer refer to example - 5 , Page No : 5.4.
Q7. Construct CFG for the language L which has all the strings which are all
palindromes over T = { a, b)
Answer:
For Answer refer to example - 6 , Page No : 5.5.
5.72 FORMAL LANGUAGES AND AUTOMATA THEORY

20. Which ofthe following gnunmarsis ambiguous?


(a) S ➔ S+SIS•Slalb (b) S ➔ alabSblaAb,A ➔ bSJaAAb
(c) S-► aBlab,A ➔ aABla, B ➔ ABblb (d)allofthe above
21 . Anystring ofterminals that can be generated bythe followingCFG
S ➔ XY
X ➔ aXlbXla
Y ➔ Ya!Ybla
(a)Has atleast two a (b)Has no ·consecutive a or b
(c) Should end in a (d)Has at least one b
22. The grammar {S ➔ aslbSlalb) is not equivalent to
(a) (a+b}*(a+b) (b) (a+b)(a+b)' (c) (a* +b)" (d)None ofthe above
23. Which ofthe followng statements is true?
i

(i) A regular set accepted bya deterministic finite automaton with n states is accepted to
final state bya detenninistic pda with n states and one pushdovm symbol.
(ii) Everyregular set accepted bya finite automaton with n states is accepted bya
deterministic pda with one state and n pushdown symbols
(iii) IfL is accepted bya deterministic pdaA, then it can be s hown that L is accepted by
a determini stic pdaA which never adds more than one symbol at a time.
(a)(i),(ii)and(iii) (b)(i)and(fo)only
(c)(ii)and(iii)only (d)(i)and(ii)only
24. Match the) e with lhe corres=ndin<>machine:
Language Machine
(i) Regular language (A)Nondetem:!inistipm:lo\'.naulomaton
(ii) DCFL (B)Turing machine
(iii)CFL (C) Detenninistic pushdown automaton
(iv)context-sensitive language (D)(Non)Detenninislicfinife.sjafea=ptor
(v) Recursive language (E)Turing machine that halts
(vi) Recursivelyenumerablel e (F) Linear-bounded automaton
(a)D ACFE B (b)DCAFEB
(c)DCA BEF (d)DCF EA B
25. ThegrdlIUDarthat generates L={ an b11 ci lncl,i = 0) is,
(a) S ➔ aAbl Sc, A ➔ ablaAb (b) S ➔ Al Sc, A ➔ ablaAb
(c)Anyoneofthetwo (d)Noneofthe two.
Automata and Compiler Design

UNIT 3
6
PUSH DOWN AUTOMATA
After going through this chapter, you should be able to understand

• Push down automata


• Acceptance by final stale and by empty stack
• Equivalence of CFL and PDA
• Interconversion
• Introduction to DCFL and DPDA

6.1 INTRODUCTION

APDA is an enhancement offinite automata(FA). Finite automata with a stack memory can be
viewed as pushdown automata. Addition ofstack memory enhances the capability ofPushdown
automata as compared to finite automata. The stack memory is potentially infinite and it is a data
structure. Its operation is based on last- in - first- out (LIFO). It means, the last object pushed
on the stack is popped first for operation. We assume a stack is long enough and linearly arranged.
We add or remove objects at the left end.

6.1.1 Model of Pushdown Automata (PDA)

A model of pushdown automata is shown in below figure. It consists of a finite tape, a reading
head, which reads from the tape, a stack memory operating in LIFO fashion.

Input Tape

Reading

.•
Head
.

• Stack
Finite State Control

FIGURE : Model of Pushdown Automata


6.50 FORMALLANGUAGESANDAUTOMATA THEORY

REVIEW QUESTIONS

Ql. What is PDA? Explain.


Answer:
For Answer refer to Topic: 6.1 , Page No : 6.1.

Q2.Obtain a PDA to accept the language l(M)={ wCwR I wE(a+b)*} where

wR is reverse of W .
Answer:
For Answer refer to example - 1 , Page No : 6.6.
Q3. Obtain a PDA to accept the language L= {·a" b"I n 2. J} by a final state.

Answer:
For Answer refer to example - 2 , Page No: 6.9.

Q4. Obtain a PDA·to accept the language L(M) = { wjw e(a +b) ° and n. (w) =11,(w)}.
Answer:
For Answer refer to example - 3 , Page No : 6.12.
QS. Obtain a PDA to accept a string of balanced parentheses. The parentheses
to be considered are ( , ) , I. ].
Answer:
For Answer refer to example - 4, Page No: 6.15.
Q6. Obtain a PDAto accept the language L = { l>jw e (a, b)•and nu (w) >n,(w)}.

Answer:
For Answer refer to example • 5 , Page No : 6.17.

Q7. Obtain a PDA to acceptthe language£= {a"binl n 2. l}.


Answer:
For Answer refer to example - 6 , Page No : 6. I 8.

You might also like