Ejemplo n.º 1
0
  @Override
  public boolean equals(Object obj) {
    if (obj == null) return false;
    if (this == obj) return true;
    if (!(obj instanceof TermCons)) return false;
    TermCons tc = (TermCons) obj;

    if (!tc.getSort().equals(this.sort)) return false;
    if (!tc.cons.equals(cons)) return false;

    if (tc.contents.size() != contents.size()) return false;

    for (int i = 0; i < tc.contents.size(); i++) {
      if (!tc.contents.get(i).equals(contents.get(i))) return false;
    }

    return true;
  }
Ejemplo n.º 2
0
 @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;
 }
Ejemplo n.º 3
0
  public TermCons(Element element, Context context) {
    super(element);
    this.sort = element.getAttribute(Constants.SORT_sort_ATTR);
    this.cons = element.getAttribute(Constants.CONS_cons_ATTR);
    this.production = context.conses.get(cons);
    assert this.production != null;

    contents = new ArrayList<Term>();
    List<Element> children = XML.getChildrenElements(element);
    for (Element e : children) contents.add((Term) JavaClassesFactory.getTerm(e));
  }
Ejemplo n.º 4
0
  public TermCons(ATermAppl atm, Context context) {
    super(atm);
    this.cons = atm.getName();
    this.sort = StringUtil.getSortNameFromCons(cons);
    this.production = context.conses.get(cons);
    assert this.production != null;

    contents = new ArrayList<Term>();
    if (atm.getArity() == 0) {
      contents = new ArrayList<Term>();
    } else if (atm.getArgument(0) instanceof ATermList) {
      ATermList list = (ATermList) atm.getArgument(0);
      for (; !list.isEmpty(); list = list.getNext()) {
        if (isColon(list.getFirst())) continue;
        contents.add((Term) JavaClassesFactory.getTerm(list.getFirst()));
      }
      contents.add(new ListTerminator(sort, null));
    } else {
      for (int i = 0; i < atm.getArity(); i++) {
        if (isColon(atm.getArgument(i))) continue;
        contents.add((Term) JavaClassesFactory.getTerm(atm.getArgument(i)));
      }
    }
  }
Ejemplo n.º 5
0
 public Term setSubterm(int idx, Term term) {
   return contents.set(idx, term);
 }
Ejemplo n.º 6
0
 public Term getSubterm(int idx) {
   return contents.get(idx);
 }