Back to From Specification to NFA. On to Introduction to Grammars and Parsing.

**Held** Wednesday, February 7, 2001

**Summary**

Today we continue our consideration of how to move from the readable but declarative regular exprssion notation to the executable but obtuse finite automaton notation.

**Assignments**

- Project Phase 1: Lexical Analyzer

**Notes**

- Quiz! (May be continued in lab tomorrow.)
- How are things going?
- I've rearranged the syllabus slightly.

**Overview**

- From NFA to DFA
- From DFA to optimal DFA
- Reminder: Lexical analysis using automata

- How do we turn this lovely NFA into a deterministic computing machine?
- Basically, we build a DFA that simultaneously follows all the paths that
we can go through in the NFA.
- Each state in the DFA is a set of states in the corresponding NFA.

- The algorithm is again fairly simple
- Terminology :
- qx is a state in the NFA and q0 is its start state
- QX is a state in the DFA and Q0 is its start state
- The eqsilon-closure of a DFA state consists of all the states
in the NFA that we can get to with epsilon moves from the states
in the DFA state.
Q0 = { q0 }

*// but there are some states we can reach from q0 at no cost*Q0 = epsilon-closure(Q0) while there are states we haven't processed pick one such state, Qn for each symbol s let tmp be a new set for each q in Qn add delta(q,s) to tmp end for tmp = epsilon-closure(tmp) if tmp is not in the DFA then let Qi be a new state Qi = tmp add Qi to the DFA else let Qi be the state equivalent to tmp end if add an edge from Qn to Qi in the automaton end for end while for each Qi if there is a q in Qi that is a final state then Qi is a final state end if end for

- When we make the determination of a final state, we use the associated token type of the highest priority final state in the NFA.

- As you may be able to tell, the resulting DFA is fairly large.
- Can we build an equivalent DFA that's smaller? Yes!
- Strategy: Group states into sets of equivalent states.
Assume all non-final states can be treated as the same state Assume all final states can be treated as the same state For each group of states treated as equivalent as the same state For each symbol, s If there are two "equivalent" states q1,q2 such that edge(q1,s) and edge(q2,s) lead to non-equivalent states, split q1 and q2 into different equivalencies figure out where the other states in the equivalency go End For // each symbol End for // each pair of states

Back to From Specification to NFA. On to Introduction to Grammars and Parsing.

[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
**Primary**

[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Quizzes]
[Readings]
[Reference]
**Sets**

[Blackboard]
[98F]
**Links**

**Disclaimer**:
I usually create these pages on the fly. This means that they
are rarely proofread and may contain bad grammar and incorrect details.
It also means that I may update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Mon Apr 30 10:51:48 2001.

This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2001S/outline.08.html`

.

You may validate
this page's HTML.

The source was last modified Mon Jan 22 10:39:10 2001.