public Grammar exportGrammar() {
		// Are any yet unconverted?
		if (objectToProduction.keySet().size() != alreadyDone.size()) {
			highlightUntransformed();
			JOptionPane
					.showMessageDialog(
							convertPane,
							"Conversion unfinished!  Objects to convert are highlighted.",
							"Conversion Unfinished", JOptionPane.ERROR_MESSAGE);
			changeSelection();
			return null;
		}
		try {
			ConvertedUnrestrictedGrammar g=getGrammar();
			ArrayList <Production> prods=new ArrayList <Production>();
			Production[] temp=g.getProductions();
			for (int i=0; i<temp.length; i++)
				prods.add(temp[i]);
			
			Collections.sort(prods, new Comparator<Production>(){
		            public int compare(Production o1, Production o2) {
		            	if (o1.getLHS().equals("S"))
		            		return -1;
		            	return (o1.getRHS().length()-o2.getRHS().length());
		            }
		    });
			ConvertedUnrestrictedGrammar gg=new ConvertedUnrestrictedGrammar();
			for (int i=0; i<temp.length; i++)
				temp[i]=prods.get(i);
			gg.setStartVariable("S");
			gg.addProductions(temp);
			FrameFactory.createFrame(gg, 0);
			return gg;
		} catch (GrammarCreationException e) {
			JOptionPane.showMessageDialog(convertPane, e.getMessage(), "Error",
					JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}