public ParseTreeTools(ATermFactory factory) { super(); parsetreeFun = factory.makeAFun("parsetree", 2, false); applFun = factory.makeAFun("appl", 2, false); prodFun = factory.makeAFun("prod", 3, false); noattrsFun = factory.makeAFun("no-attrs", 0, false); attrsFun = factory.makeAFun("attrs", 1, false); termFun = factory.makeAFun("term", 1, false); consFun = factory.makeAFun("cons", 1, false); }
/** * Filter non-primes * * @param numbers */ 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); }
/** * Generate a list of consecutive numbers. * * @param max */ private ATermList generateNumbers(int max) { ATermList numbers = factory.makeList(); for (int i = max; i > 0; i--) numbers = factory.makeList(factory.makeInt(i), numbers); return numbers; }
public void test1() { assertTrue(getPrimes(30) == factory.parse("[1,2,3,5,7,11,13,17,19,23,29]")); assertTrue(getPrimes(500).getLength() == 96); }