public RegularGrammar convertToRegularGrammar(Automaton automaton) {
		/** check if automaton is fsa. */
		if (!(automaton instanceof FiniteStateAutomaton)) {
			System.err.println("ATTEMPTING TO CONVERT NON FSA TO "
					+ "REGULAR GRAMMAR");
			return null;
		}

		RegularGrammar grammar = new RegularGrammar();
		/** map states in automaton to variables in grammar. */
		initializeConverter(automaton);
		/**
		 * go through all transitions in automaton, creating production for
		 * each.
		 */
		Transition[] transitions = automaton.getTransitions();
		for (int k = 0; k < transitions.length; k++) {
			Production production = getProductionForTransition(transitions[k]);
			grammar.addProduction(production);
		}

		/**
		 * for all final states in automaton, add lambda production.
		 */
		State[] finalStates = automaton.getFinalStates();
		for (int j = 0; j < finalStates.length; j++) {
			Production lprod = getLambdaProductionForFinalState(automaton,
					finalStates[j]);
			grammar.addProduction(lprod);
		}

		return grammar;
	}