advertisement

CS 5300 Compiler Design Fall 2006 Converting an NFA to a DFA 1. Construct a table with the following columns; MARKING STATE PATH_TO T_SET Y_SET MARKING STATE PATH_TO T_SET indicates all paths out of this STATE have been considered; is the name of a DFA state; is a path in the DFA; is the set of states in the NFA to which there is a path over a given symbol; Y_SET is -closure(T_SET) or the set of all states in the NFA which can be reached over paths from any state in the T_SET. (note: this always includes the T_SET states) To avoid confusion, we will use numbers for NFA states and capital letters for DFA states. 2. Initialize the table with the DFA start state as the first row; STATE = A, T_SET = [0] 3. Calculate Y_SET for the start state A. 4. While there is an unmarked state, do; 1) select and mark a state; 2) consider all possible paths out of that state -- for each possible symbol; a) add a row with PATH_TO as a path from the current state over the current symbol. b) calculate T_SET for this new row using the states in the current state's Y_SET. c) if this T_SET is unique from all other T_SETs, do; i -- give this row a new STATE name, ii - calculate Y_SET 5. The STATE names and PATH_TO paths now define a DFA corresponding to the NFA. Example: DFA (a|b)*abb MARKING x x x STATE A B C x D x E PATH_TO A-a A-b B-a B-b C-a C-b D-a D-b E-a E-b T_SET [0] [3,8] [5] [3,8] [5,9] [3,8] [5] [3,8] [5,10] [3,8] [5] Y_SET NFA [0,1,2,4,7] [1,2,3,4,6,7,8] [1,2,4,5,6,7] [1,2,4,5,6,7,9] [1,2,4,5,6,7,10]