re
Class NFA

java.lang.Object
  extended by re.NFA

public class NFA
extends Object

A class to represent an NFA. You should create an NFA from a regular expression using this class. States are represented as numbers (with 0 always being the start state). Transitions can be lablled with 'a' - 'z', or '@' to indicate an epsilon transition. The constructor for NFA creates an automaton containing only state 0 and no transitions. The other NFA methods permit you to add new states and edges to the NFA, as well as to print out an NFA in a form suitable for the NFASimulator (or for viewing with dot).


Constructor Summary
NFA()
          Create a new NFA with state 0.
 
Method Summary
 void addTransition(int start, int end, char c)
          Add a transition to the NFA.
 int newState()
          Add a new state to the NFA and return its id number.
 void printDot()
          Creates a file nfa.dot containing a graphical description of the NFA.
 void setAcceptState(int state)
          Set the accepting state for the NFA.
 String toString()
          Return a String representing the NFA in a way that can be read in by nfa.NFASimulator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NFA

public NFA()
Create a new NFA with state 0.

Method Detail

setAcceptState

public void setAcceptState(int state)
Set the accepting state for the NFA. Must be a previously allocated state.


addTransition

public void addTransition(int start,
                          int end,
                          char c)
Add a transition to the NFA.

Parameters:
start - must be a valid state in the NFA
end - must be a valid state in the NFA
c - the character on the edge. 'a' <= c <= 'z', or c == '@' for epsilon

newState

public int newState()
Add a new state to the NFA and return its id number.


toString

public String toString()
Return a String representing the NFA in a way that can be read in by nfa.NFASimulator.

Overrides:
toString in class Object

printDot

public void printDot()
Creates a file nfa.dot containing a graphical description of the NFA. That file can then be processed with the dot utility.