Professional Documents
Culture Documents
Science (COSC-3302),
Lecture 2 (prepared after
Chapter 2 of Martins 2011
Stefan Andrei
textbook)
04/22/16
Course content
1.1. Mathematical Tools and Techniques (Chapter 1)
1.2. Finite Automata and the Languages they Accept (Chapter 2)
1.3. Regular Expressions, Nondeterminism, and Kleenes Theorem (Chapter 3)
Exam 1
2.1. Context-Free Languages (Chapter 4)
2.2. Pushdown Automata (Chapter 5)
2.3. Context-Free and Non-Context-Free Languages (Chapter 6)
Exam 2
3.1. Turing Machines (Chapter 7)
3.2. Recursively Enumerable Languages (Chapter 8)
3.3. Undecidable Problems (Chapter 9)
3.4. Computable Functions (Chapter 10)
3.5. Introduction to Computational Complexity (Chapter 11)
Exam 3
04/22/16
Overview of Previous
Lecture
1.
2.
3.
4.
5.
6.
04/22/16
3.
4.
5.
6.
04/22/16
04/22/16
04/22/16
10
11
FAs are ideally suited for lexical analysis, the first stage in
compiling a computer program.
Real-world example: the drink machine from the
hallway!
A lexical analyzer takes a string of characters and provides
a string of tokens.
Tokens have a simple structure: e.g., 41.3, main.
The next slide shows an FA that accepts tokens for a
simple language based on C:
The only tokens are identifiers, semicolons, =, aa, and
numeric literals; tokens are separated by spaces.
Accepting states represent scanned tokens; each
accepting state represents a category of token.
04/22/16
12
D is any digit.
L is a lowercase letter
other than a.
M is D or L.
N is D or L or a.
is a space.
All transitions not
shown explicitly go to
an error state and
stay there.
04/22/16
13
04/22/16
14
04/22/16
15
04/22/16
16
04/22/16
17
Finite Automata:
Examples and
Definitions (cont)
18
Definition:
04/22/16
19
04/22/16
20
Q = Q1 Q2
q0 = (q1, q2)
Then, if:
A = {(p, q) | p A or q A }, M accepts L L
1
2
1
2
04/22/16
21
Two
Languages (contd.)
the state sets, and draw the necessary transitions.
04/22/16
22
23
24
Distinguishing One
String from Another
Any three-state FA, such as the one that accepts the strings
ending in aa, ignores, or forgets, a lot of information:
aba and aabbabbabaaaba lead to the same state (q ); there
1
is no way for the FA to remember which string has been
seen.
aba and ab, however, lead to different states; the essential
difference is that one ends with a and the other does not.
aba and ab are distinguishable with respect to the language
accepted by the FA; there is at least one string z (such as a)
so that abaz is in the language (i.e., is accepted) and abz is
not, or vice versa.
(get a *) Do ababa and babab go to the same state? Justify.
04/22/16
25
26
2.
If x and y are two strings in * that are Ldistinguishable, then *(q0, x) *(q0, y).
For every n 2, if there is a set of n pairwise Ldistinguishable strings in *, then Q must contain
at least n states.
Example: This theorem shows why we need at
least three states in any machine that accepts the
language L of strings ending in aa: {, a, aa}
contains 3 pairwise L-distinguishable strings.
04/22/16
27
28
29
30
04/22/16
31
04/22/16
32
04/22/16
33
04/22/16
34
by an FA.
04/22/16
35
2.
3.
04/22/16
36
04/22/16
37
38
39
04/22/16
40
q0 = [],
A = {q QL | q L},
For every x * and every , ([x], ) = [x ].
04/22/16
41
04/22/16
42
04/22/16
43
04/22/16
44
04/22/16
45
1.
2.
3.
4.
5.
6.
04/22/16
46
04/22/16
47
04/22/16
48
The table DISTINCT after executing step (1) and one iteration of step (2) is:
04/22/16
49
The table DISTINCT after executing another iteration of step (2) is:
04/22/16
50
Summary
1.
2.
3.
4.
5.
6.
04/22/16
51
Reading suggestions
04/22/16
52
Coming up next
04/22/16
53
04/22/16
54