public void match(ArrayList<Token> rhs) { outer: for (Token i : rhs) { // System.out.println("i:" + i); if (i.getClass().getName().equals("compiler.Terminal")) { matchTerminal((Terminal) i); } else if (i.getClass().getName().equals("compiler.NonTerminal")) { NonTerminal iNonTerminal = (NonTerminal) i; ArrayList<Integer> lhses = getIndexOfRulesWithLeftHandSide(gr.rules, iNonTerminal); for (Integer j : lhses) { if (gr.getFirsts(gr.rules.get(j).getRightSide()) .contains(Terminal.getTerminalbyString(lookAhead))) { // System.out.println("using rule:" + // gr.rules.get(j).getRightSide()); match(gr.rules.get(j).getRightSide()); continue outer; } } /// no rule with input in first if (iNonTerminal.getFirsts().contains(Terminal.getTerminal("Epsilon"))) { if (iNonTerminal.getFollows().contains(Terminal.getTerminalbyString(lookAhead))) { ArrayList<Integer> indexOfRulesWithLeftHandSide = getIndexOfRulesWithLeftHandSide(gr.rules, iNonTerminal); for (Integer j : indexOfRulesWithLeftHandSide) { if (gr.getFirsts(gr.rules.get(j).getRightSide()) .contains(Terminal.getTerminal("Epsilon"))) { match(gr.rules.get(j).getRightSide()); continue outer; } } } } if (iNonTerminal.getFollows().contains(Terminal.getTerminalbyString(lookAhead))) { System.err.println("missing " + iNonTerminal.getDesc() + " ,insert it"); } else { System.err.println("misplaced " + lookAhead + " I'm Skipping it!"); lookAhead = getNextToken(); } } else if (i.getClass().getName().equals("compiler.Procedure")) { runProcedure(i.getName()); } } }
public ConsoleReader(final InputStream in, final Writer out, final InputStream bindings) throws IOException { this(in, out, bindings, Terminal.getTerminal()); }