}
private void emitGetActions(Writer writer, ParseTable parseTable,
Map<Rule, RID> rulenums) throws IOException {
Map<Set<Action>,Integer> actionids = new HashMap<Set<Action>,Integer>() ;
for(Map.Entry<Integer, ParseTableState> e: parseTable.states.entrySet()) {
ParseTableState pts = e.getValue();
for(Map.Entry<String, Set<Action>> e2: pts.actions.entrySet()) {
Set<Action> actions = e2.getValue();
Integer id = actionids.get(actions) ;
if (id == null) {
id = actionids.size();
actionids.put(actions,id) ;
writer.write("\tprivate static final Action[] ACTION"+id+" = {\n") ;
String delim = "" ;
for(Action a: actions) {
writer.write("\t\t"+delim) ;
delim = "," ;
switch(a.getType()) {
case accept:
writer.write("new AcceptAction(RULE"+rulenums.get(((AcceptAction)a).r).rulenum+")\n") ;
break ;
case shift:
writer.write("new ShiftAction("+((ShiftAction)a).s+")\n") ;
break ;
case reduce:
writer.write("new ReduceAction(RULE"+rulenums.get(((ReduceAction)a).r).rulenum+")\n") ;
break ;
}
}
writer.write("\t} ;\n") ;
}
}
}
for(Map.Entry<Integer, ParseTableState> e: parseTable.states.entrySet()) {
ParseTableState pts = e.getValue();
if (!pts.actions.isEmpty()) {
Map<Set<Action>,List<String>> revmap = new HashMap<Set<Action>,List<String>>() ;
for(Map.Entry<String, Set<Action>> e2: pts.actions.entrySet()) {
Set<Action> actions = e2.getValue() ;
String sym = e2.getKey() ;
List<String> l = revmap.get(actions) ;
if (l == null) {
l = new ArrayList<String>() ;
revmap.put(actions, l) ;
}
l.add(sym) ;
}
writer.write("\tprivate static final Action[] getActions"+e.getKey()+"(String sym) {\n") ;
writer.write("\t\t\tswitch(sym.hashCode()) {\n") ;
for(Map.Entry<Set<Action>,List<String>> e2: revmap.entrySet()) {
Set<Action> actions = e2.getKey() ;
List<String> l = e2.getValue() ;
for(String sym: l) {
writer.write("\t\t\tcase "+sym.hashCode()+":\n") ;
}
writer.write("\t\t\t\treturn ACTION"+actionids.get(actions)+";\n") ;
}
writer.write("\t\t\t}\n") ;
writer.write("\t\t\treturn null;\n") ;
writer.write("\t}\n") ;
}
}
writer.write("\tpublic Action[] getActions(int state, String sym) {\n") ;
writer.write("\t\tswitch(state) {\n") ;
for(Map.Entry<Integer, ParseTableState> e: parseTable.states.entrySet()) {
ParseTableState pts = e.getValue();
if (!pts.actions.isEmpty()) {
writer.write("\t\tcase "+e.getKey()+": return getActions"+e.getKey()+"(sym);\n") ;
}
}
writer.write("\t\t}\n") ;