Professional Documents
Culture Documents
Compiler Design and Construction6
Compiler Design and Construction6
and Construction
Scanner Regular Expressions to DFA
Announcements
PROG 1 Feedback
Linux Install Fest When?
Saturday?, Fliers, CDROMS, Bring
Laptops (do at own risk)
LUG
Understanding Editors (Eclipse, Vi,
Emacs)
Scanners
Source
Code
Lexical Analyzer
(Scanner)
Deterministic
Regular
Finite
Expression
State
Automata
Nondeterministic
Finite
State
Automata
Token
Stream
Regular Expressions
RE to NFA: Step 1
(a(a|b))*
Leaf Nodes are either
members of
or
Internal Nodes are operators
cat, |, *
RE to NFA: Step 2
Leaf Nodes
Either or member of
Cat
a
Internal Nodes
Or
Concatination
Kleene Closure
Or Node
l
Concatenation Node
l
Kleene Closure
Try It
NFA to DFA
State
S
A
B
B
B
B
Operations on NFA
if (U not in DFA)
add U unmarked to DFA
transition[T,a]=U;
Try it
Take NFA from previous example and
construct DFA
Corresponding DFA
b
C
1,2,4,
5,6,7
b
NewS
S,1,2,4,7
a
B
1,2,3,4
6,7,8
D
1,2,4,5,
6,7,9
b
a
NewF
1,2,4,5,
6,7,F
Efficiency of Algorithms
RE -> NFA
O(|r|) where |r| is the size of the RE
More Practice
Convert RE to NFA
((|a)b*)*
2
b
Solution to Practice
RE to NFA
Solution to Practice
NFA to DFA
a
A
2
a
NewS
S,1,3
b
B
4
Summary of Scanners
Lexemes
Tokens
Regular Expressions, Extended RE
Regular Definitions
Finite Automata (DFA & NFA)
Conversion from RE->NFA->DFA
JLex