The NextState() Function
next = NextState(current,ch);
Given the current state of the DFA, current, and the current input character, ch, return the next state.
Determines the next state by one of:
- indexing a Transition Table
- switch statements
- some if statements
/* Use a transition table to get the next state:
*/
State
NextState(State current, int ch){
return Table[current][Column(ch)];
}
/* Turn a character into a column index:
*/
int
Column(int ch){
if( isascii(ch) && isdigit(ch) ) return 0;
if( isascii(ch) && isalpha(ch) ) return 1;
switch( ch ){
case +: return 2;
case -: return 3;
case EOF: return 4; /* needs special handling */
default: return 5;
}
}