Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Contextfree and Noncontextfree
Languages
We have used the closure properties and
the pumping lemma to show that languages
are not regular.
We cannot use the previous pumping
lemma to show that a language is not
contextfree.
The idea
If G is a grammar,
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Converting CFGs to PDAs
Theorem: Let G = (V, , R, S) be a CFG.
Then there is a PDA M so that L(M) =
L(G).
Example: CFGs to PDAs
Given the CFG G below, create the
corresponding PDA M
R R + T  T
T T * F  F
F [R]a
1
Example: Converting CFGs to
PDAs
Given
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Deductive Proofs
Sequence of statements leading from a
hypothesis H to a conclusion statement C.
Each step must follow by a logical principle.
Follow means modus ponens: if A then B.
Typically, the hypothesis consists of several
independent statements con
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
TM Example
Construct a TM for the nonregular language
pal of palindromes over cfw_a, b.
Consider the palindromes:
aabaaaba
aabaab
Closure Properties
Recursively enumerable languages are
closed under union, intersection,
concatenation, and Kleene star.
1
T
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
ChurchTuring Thesis
PDAs are a restricted model of
computation, since there are languages that
can be solved by an algorithm but that are
not accepted by any PDA (e.g. cfw_aibici  i 0
ChurchTuring Thesis
A Turing machine models a human being
solving a
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
PDAs to CFGs
We have learned how to generate PDAs
given a CFG, but how do we derive a CFG
for a given PDA?
Theorem: If a PDA recognizes a language,
the it is context free.
PDAs to CFGs: Final State
Acceptance
Theorem: Assume that M = (Q, , , , q0,
F, Z0)
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Logistics
CS 252
Theory of Computation
Available on the web.
Lecture Notes
Assignments
Schedule
Dr. Julie A. Adams
Logistics
Class time: Tu. Thurs. 11:00 AM 12:15 PM
Location: Room 306, Featheringill Hall
Instructor: Julie A. Adams
Office: Room 359, Jaco
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Languages
Is cfw_aibi  i N a regular language?
A Criterion for Regularity
Definition: Let L be a language over . Two
strings x, y * are distinguishable with
respect to L iff there exists a string z*
such that (xzL yzL).
1
A Criterion for Regularity
Theo
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Finite State Machines
Construct a FA that recognizes the
language of all strings of 0s and 1s of
length at least 1 that if they were
interpreted as binary representations of
integers, would represent integers evenly
divisible by 3. The FA should accept th
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Regular Expressions, FAs and NFAs
Kleenes Theorem: Any regular language
can be accepted by a FA, and the
language accepted by any finite
automaton is regular.
Kleenes Theorem
Kleenes Theorem: A language L over the
alphabet is regular if and only if there
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
CFLs
We can use CFGs to give us all strings in a
language.
How do we determine if a given string is in
the language?
Algorithms that determine if a given string is in a
contextfree language are called parsers.
Often, parsing algorithms require that the
g
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
NFAs versus FAs
Show that: For any FA
M = (Q, , , q0, F), there exists an NFA
M1 = (Q1, , 1, q1, F1) such that
L(M) = L(M1).
NFAs versus FAs
NFAs may look more powerful than FAs,
but they are not!
Theorem: For any NFA
M = (Q, , , q0, F), there exists a FA
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
Nondeterminism
Look at the following transition diagram for
the set of strings over cfw_a, b that contain at
most 2 as.
Why is this not a transition diagram of a FA?
When does this machine accept a string?
b
b
a
a
b
a
a
Nondeterminism
Look at the followin
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
NFA to DFA example
2
a
1
b
4
3
a
1. Convert NFA to an NFA
NFA to DFA example
2. Convert NFA to a DFA
1
Regular Languages and
Expressions
A regular language over is a language
that can be built from , cfw_, and cfw_a for any
a , using operators union,
c
Theory of Automata, Formal Languages and Computation
CS 252

Spring 2008
ContextFree Grammars
A common method of defining the syntax
of programming languages are BackusNaur form (BNF), syntax diagrams, and
contextfree grammars.
ContextFree Grammars
Definition: A contextfree grammar (CFG)
is a quadruple G = (V, , R, S) wher