public ContextFreeGrammar convertToContextFreeGrammar(Automaton automaton) {
		/** check if automaton is pda. */
		if (!(automaton instanceof PushdownAutomaton))
			throw new IllegalArgumentException(
					"automaton must be PushdownAutomaton");

		if (!isInCorrectFormForConversion(automaton))
			throw new IllegalArgumentException(
					"automaton not in correct form for conversion to CFG");

		initializeConverter();

		ArrayList list = new ArrayList();
		ContextFreeGrammar grammar = new ContextFreeGrammar();

		Transition[] transitions = automaton.getTransitions();
		for (int k = 0; k < transitions.length; k++) {
			list.addAll(createProductionsForTransition(transitions[k],
					automaton));
		}

		Iterator it = list.iterator();
		while (it.hasNext()) {
			Production p = (Production) it.next();
			grammar.addProduction(getSimplifiedProduction(p));
		}

		return grammar;
	}