public static Grammar getTerminalGrammar(Grammar grammar) {
		Grammar g = new ContextFreeGrammar();
		Set terminalVars = getCompleteUsefulVariableSet(grammar);
		Production[] prods = grammar.getProductions();
		for (int i = 0; i < prods.length; i++) {
			Set v = new HashSet(Arrays.asList(prods[i].getVariables()));
			v.removeAll(terminalVars);
			if (v.size() > 0)
				continue;
			// Production has no variables that aren't terminal derivers!
			g.addProduction(prods[i]);
		}
		g.setStartVariable(grammar.getStartVariable());
		return g;
	}