Esempio n. 1
0
 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");
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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;
 }