Package org.allspice.parser.parsetable.ParseTable

Examples of org.allspice.parser.parsetable.ParseTable.ParseTableState


  }
  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") ;
View Full Code Here


    writer.write("\t}\n") ;
  }
  private void emitGetGoto(Writer writer, ParseTable parseTable)
      throws IOException {
    for(Map.Entry<Integer, ParseTableState> e: parseTable.states.entrySet()) {
      ParseTableState pts = e.getValue();
      if (!pts.gotos.isEmpty()) {
        writer.write("\tprivate static final int getGoto"+e.getKey()+"(String sym) {\n") ;
        writer.write("\t\tswitch(sym.hashCode()) {\n") ;
        for(Map.Entry<String, Integer> e2: pts.gotos.entrySet()) {
          writer.write("\t\tcase "+e2.getKey().hashCode()+": return "+e2.getValue()+";\n") ;
        }
        writer.write("\t\t}\n") ;
        writer.write("\t\tthrow new org.allspice.parser.parsetable.UndefinedRuleException("+e.getKey()+",sym);\n") ;
        writer.write("\t}\n") ;
      }
    }
    writer.write("\tpublic int getGoto(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.gotos.isEmpty()) {
        writer.write("\t\tcase "+e.getKey()+": return getGoto"+e.getKey()+"(sym) ;\n") ;
      }
    } 
    writer.write("\t\t}\n") ;
View Full Code Here

TOP

Related Classes of org.allspice.parser.parsetable.ParseTable.ParseTableState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.