コード例 #1
0
ファイル: Production.java プロジェクト: JoeOsborn/k
  @Override
  public int hashCode() {
    int hash = 0;
    if (sort != null) hash += sort.hashCode();

    for (ProductionItem pi : this.items) hash += pi.hashCode();
    return hash;
  }
コード例 #2
0
ファイル: Production.java プロジェクト: JoeOsborn/k
 public int getArity() {
   int arity = 0;
   for (ProductionItem i : items) {
     if (i.getType() == ProductionType.USERLIST) arity += 2;
     if (i.getType() == ProductionType.SORT) arity++;
   }
   return arity;
 }
コード例 #3
0
ファイル: Production.java プロジェクト: JoeOsborn/k
 public boolean hasTerminalToLeft(int idx) {
   int arity = 0;
   for (int i = 0; i < items.size(); i++) {
     ProductionItem item = items.get(i);
     if (item.getType() == ProductionType.USERLIST) {
       if (idx == arity) return false;
       if (idx == arity + 1) return !((UserList) item).getSeparator().equals("");
       arity += 2;
     } else if (item.getType() == ProductionType.SORT) {
       if (idx == arity) return i != 0 && items.get(i - 1).getType() == ProductionType.TERMINAL;
       arity++;
     }
   }
   throw new IllegalArgumentException("Index not found in production");
 }
コード例 #4
0
ファイル: Production.java プロジェクト: JoeOsborn/k
 public String getChildSort(int idx) {
   int arity = -1;
   if (items.get(0).getType() == ProductionType.USERLIST) {
     if (idx == 0) {
       return ((UserList) items.get(0)).getSort();
     } else {
       return this.getSort();
     }
   }
   for (ProductionItem i : items) {
     if (i.getType() != ProductionType.TERMINAL) arity++;
     if (arity == idx) {
       return ((Sort) i).getName();
     }
   }
   return null;
 }
コード例 #5
0
ファイル: Production.java プロジェクト: JoeOsborn/k
 private String getPrefixLabel() {
   String label = "";
   for (ProductionItem pi : items) {
     switch (pi.getType()) {
       case SORT:
         label += "_";
         break;
       case TERMINAL:
         label += ((Terminal) pi).getTerminal();
         break;
       case USERLIST:
         label += "_" + ((UserList) pi).separator + "_";
         break;
     }
   }
   return label;
 }
コード例 #6
0
ファイル: TermCons.java プロジェクト: rusurazvangabriel/k
 @Override
 public String toString() {
   String str = "";
   if (production.items.size() > 0) {
     if (production.items.get(0) instanceof UserList) {
       String separator = ((UserList) production.items.get(0)).separator;
       str = contents.get(0) + " " + separator + " " + contents.get(1) + " ";
     } else
       for (int i = 0, j = 0; i < production.items.size(); i++) {
         ProductionItem pi = production.items.get(i);
         if (pi instanceof Terminal) {
           String terminall = pi.toString();
           terminall = terminall.substring(1, terminall.length() - 1);
           str += terminall + " ";
         } else if (pi instanceof Sort) str += contents.get(j++) + " ";
       }
   }
   return str;
 }