@Override
	protected ConvertedUnrestrictedGrammar getGrammar() {
		// TODO Auto-generated method stub
		
		//Put error check here
		
		int rows = getModel().getRowCount();
		ConvertedUnrestrictedGrammar grammar = new ConvertedUnrestrictedGrammar();
		grammar.setStartVariable("S");
		ArrayList <Production> productions = new ArrayList <Production>();
		for (int i = 0; i < rows; i++) {
			Production production = getModel().getProduction(i);
			if (production == null)
				continue;
		//	production = converter.getSimplifiedProduction(production);
			productions.add(production);
		}

		Collections.sort(productions, new Comparator() {
			public int compare(Object o1, Object o2) {
				Production p1 = (Production) o1, p2 = (Production) o2;
				if ("S".equals(p1.getLHS())) {
					if (p1.getLHS().equals(p2.getLHS()))
						return 0;
					else
						return -1;
				}
				if ("S".equals(p2.getLHS()))
					return 1;
				return p2.getLHS().compareTo(p1.getRHS());
			}

			public boolean equals(Object o) {
				return false;
			}
		});
		for (int i=0; i<productions.size(); i++)
		{
			grammar.addProduction(productions.get(i));
		}

	/*	UselessProductionRemover remover = new UselessProductionRemover();
		
		Grammar g2 = UselessProductionRemover
				.getUselessProductionlessGrammar(grammar);
		
		if (g2.getTerminals().length==0)
		{
			System.out.println("Error : This grammar does not accept any Strings. ");
		}
		Production[] p1 = grammar.getProductions();
		Production[] p2 = g2.getProductions();
		if (p1.length > p2.length) {
			UselessPane up = new UselessPane(new GrammarEnvironment(null), grammar);
			UselessController controller=new UselessController(up, grammar);
			controller.doAll();
			grammar=controller.getGrammar();
		}*/
		return grammar;

	}