lec08mod

# lec08mod - CS415 Compilers Lexical Analysis These slides...

This preview shows pages 1–7. Sign up to view the full content.

CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture 8 2 cs415, spring 10 Review: Automating Scanner Construction RE NFA ( Thompson’s construction ) Build an NFA for each term Combine them with ε -moves NFA DFA subset construction ) Build the simulation DFA Minimal DFA Hopcroft’s algorithm DFA RE (Not part of the scanner construction) All pairs, all paths problem Take the union of all paths from s 0 to an accepting state minimal DFA RE NFA DFA The Cycle of Constructions
Lecture 8 3 cs415, spring 10 RE NFA using Thompson’s Construction Key idea NFA pattern for each symbol and each operator Each NFA has a single start and accept state Join them with ε moves in precedence order S 0 S 1 a NFA for a S 0 S 1 a S 3 S 4 b NFA for ab ε NFA for a | b S 0 S 1 S 2 a S 3 S 4 b S 5 ε εε ε S 0 S 1 ε S 3 S 4 ε NFA for a * a ε ε Ken Thompson, C ACM , 1968

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture 8 4 cs415, spring 10 Example of Thompson’s Construction Let’s try a ( b | c ) * 1. a , b , & c 2. b | c 3. ( b | c ) * S 0 S 1 a S 0 S 1 b S 0 S 1 c S 2 S 3 b S 4 S 5 c S 1 S 6 S 0 S 7 ε ε εε S 1 S 2 b S 3 S 4 c S 0 S 5 ε ε ε ε
Lecture 8 5 cs415, spring 10 Example of Thompson’s Construction ( con’t) 4. a ( b | c ) * Of course, a human would design something simpler . .. S 0 S 1 a b | c But, we can automate production of the more complex one . .. S 0 S 1 a ε S 4 S 5 b S 6 S 7 c S 3 S 8 S 2 S 9 ε ε εε

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture 8 6 cs415, spring 10 NFA DFA with Subset Construction Need to build a simulation of the NFA Two key functions Move(s i , a ) is set of states reachable from s by a ε -closure(s ) is set of states reachable from s by The algorithm: Start state derived from s 0 of the NFA Take its ε -closure S 0 = ε -closure(s 0 ) Take the image of S 0 , move(S 0 , a) for each a Σ , and take its ε -closure Iterate until no more states are added Sounds more complex than it is…
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 23

lec08mod - CS415 Compilers Lexical Analysis These slides...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online