internal override bool match(ATerm pattern, ArrayList list) { if (pattern.getType() == ATermType.LIST) { ATermList l = (ATermList)pattern; if (l.isEmpty()) { return(this.isEmpty()); } if (l.getFirst().getType() == ATermType.PLACEHOLDER) { ATerm ph_type = ((ATermPlaceholder)l.getFirst()).getPlaceholder(); if (ph_type.getType() == ATermType.APPL) { ATermAppl appl = (ATermAppl)ph_type; if (appl.getName().Equals("list") && appl.getArguments().isEmpty()) { list.Add(this); return(true); } } } if (!isEmpty()) { ArrayList submatches = first.match(l.getFirst()); if (submatches == null) { return(false); } list.AddRange(submatches); submatches = next.match(l.getNext()); if (submatches == null) { return(false); } list.AddRange(submatches); return(true); } else { return(l.isEmpty()); } } return(base.match(pattern, list)); }
public override void visitList(ATermList list) // throws VisitFailure { while (!list.isEmpty()) { visitChild(list.getFirst()); list = list.getNext(); if (!list.isEmpty()) { stream.Write(','); position++; } } }
public virtual ATermList getPrefix() { ATermList cur, next; ArrayList elems; if (isEmpty()) { return(this); } cur = this; elems = new ArrayList(); while (true) { next = cur.getNext(); if (next.isEmpty()) { cur = ((PureFactory)getFactory()).getEmpty(); for (int i = elems.Count - 1; i >= 0; i--) { cur = cur.insert((ATerm)elems[i]); } return(cur); } else { elems.Add(cur.getFirst()); cur = cur.getNext(); } } }
public virtual ATermList reverse() { ATermList cur = this; ATermList reverse = this.getEmpty(); while (!cur.isEmpty()) { reverse = reverse.insert(cur.getFirst()); cur = cur.getNext(); } return(reverse); }
/** * Filter non-primes */ private ATermList filterNonPrimes(ATermList numbers) { ATermList primes = factory.makeList(); numbers = numbers.getNext(); while(!numbers.isEmpty()) { ATermInt prime = (ATermInt)numbers.getFirst(); numbers = filterMultiples(prime.getInt(), numbers); primes = primes.append(prime); } return factory.makeList(factory.makeInt(1), primes); }
/** * Filter non-primes */ private ATermList filterNonPrimes(ATermList numbers) { ATermList primes = factory.makeList(); numbers = numbers.getNext(); while (!numbers.isEmpty()) { ATermInt prime = (ATermInt)numbers.getFirst(); numbers = filterMultiples(prime.getInt(), numbers); primes = primes.append(prime); } return(factory.makeList(factory.makeInt(1), primes)); }
public virtual ATermList concat(ATermList rhs) { if (isEmpty()) { return(rhs); } if (next.isEmpty()) { return(rhs.insert(first)); } return(next.concat(rhs).insert(first)); }
public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos) { ATerm[] arg_array; arg_array = new ATerm[list.getLength()]; int i = 0; while (!list.isEmpty()) { arg_array[i++] = list.getFirst(); list = list.getNext(); } return(makeAppl(fun, arg_array, annos)); }
public virtual void visitChild(ATerm child) // throws VisitFailure { if (table != null) { int abbrev; if (table.Contains(child)) { abbrev = (int)table[child]; emitAbbrev(abbrev); return; } } int start = position; if (child.getType() == ATermType.LIST) { stream.Write('['); position++; } visit(child); if (child.getType() == ATermType.LIST) { stream.Write(']'); position++; } ATermList annos = child.getAnnotations(); if (!annos.isEmpty()) { stream.Write('{'); position++; visit(annos); stream.Write('}'); position++; } if (table != null) { int length = position - start; if (length > PureFactory.abbrevSize(next_abbrev)) { int key = next_abbrev++; // Or should this be ++next_abbrev?? (merijn) table.Add(key, child); } } }
public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos) { ATerm[] arg_array; arg_array = new ATerm[list.getLength()]; int i = 0; while (!list.isEmpty()) { arg_array[i++] = list.getFirst(); list = list.getNext(); } return makeAppl(fun, arg_array, annos); }
public virtual ATermList getPrefix() { ATermList cur, next; ArrayList elems; if (isEmpty()) { return this; } cur = this; elems = new ArrayList(); while (true) { next = cur.getNext(); if (next.isEmpty()) { cur = ((PureFactory) getFactory()).getEmpty(); for (int i = elems.Count - 1; i >= 0; i--) { cur = cur.insert((ATerm) elems[i]); } return cur; } else { elems.Add(cur.getFirst()); cur = cur.getNext(); } } }