[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
Held Friday, September 11, 1998
Notes
/usr/local/student/courses/csc362
/**
* Find the first token in the candidate string, starting
* at a particular position.
*/
public token findToken(String candidate, starting_pos) {
State current_state = q0;
for i = starting_pos to the length of candidate
current_state = delta(current_state,candidate.symbolAt(i))
if current_state is a final state
final_found = current_state
final_pos = i
end if
if current_state is undefined then
exit the for loop
end if
end for
if (final_found is defined) then
return the token given by final_found at position final_pos
else
no token can be found
end if
} // findToken
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
Back to Introduction to finite automata. Back to Introduction to grammars and parsing.
[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Mon Sep 14 10:53:20 1998.
This page generated on Wed Sep 16 11:21:17 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu