protected Grammar getGrammar() {
		int rows = getModel().getRowCount();
		RegularGrammar grammar = new RegularGrammar();
		grammar.setStartVariable("S");
		ArrayList productions = new ArrayList();
		for (int i = 0; i < rows; i++) {
			Production production = getModel().getProduction(i);
			if (production == null)
				continue;
			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 p1.getLHS().compareTo(p2.getRHS());
			}

			public boolean equals(Object o) {
				return false;
			}
		});
		Iterator it = productions.iterator();
		while (it.hasNext())
			grammar.addProduction((Production) it.next());
		return grammar;
	}