    /**
       Compiles a regular expression into a finite automaton
       by one of the possible methods implementing the interface
       {@link ExpressionCompiler ExpressionCompiler}
       Usage: <code>java  CompileExpression Method  Option expression</code>
       The only method presently available is T (Thomson's algorithm
       using {@link ThompsonCompiler ThompsonCompiler}).
       The options available are:<UL>
       <li> N to produce an NFA
       <li> D to produce a DFA
       <li> M to produce the minimal automaton.
       </ul>

    */
public class CompileExpression {
	public static void main(String[] args) throws Exception{
      String method = args[0];
      String option = args[1];
      if(method.equals("T")){ //Thompson's algorithm
	  System.out.println("Thompson's algorithm");
	  ExpressionCompiler ec = new ThompsonCompiler();
	  NFA nfa = ec.toNFA(args[2]);
	  if(option.equals("N")){   //NFA
	      System.out.println("NonDeterministic automaton:\n" + nfa);
	      return;
	  }
	  DFA dfa = nfa.toDFA3();
	  if(option.equals("D")){
	      System.out.println("Deterministic automaton\n" + dfa);
	      return;
	  }
	  DFA m = DFA.minimize(dfa, new NMinimizer());
	  if(option.equals("M")){
	      System.out.println("Minimal automaton\n" + m);
	  }
      }
    }
}
