Example #1
0
        public virtual ATermAppl setArgument(ATerm newarg, int index)
        {
            ATerm[] newargs = (ATerm[])args.Clone();
            newargs[index] = newarg;

            return(make(fun, newargs, getAnnotations()));
        }
Example #2
0
        public virtual void TestFileParser()
        {
            factory = Tester.theFactory;
//			try
//			{

            StreamWriter output = new StreamWriter("testFileParser.txt");
            string       s      = factory.parse("f(a,g(b))").ToString();

            output.Write(s);
            output.Close();

            FileStream input  = new FileStream("testFileParser.txt", FileMode.Open);
            ATerm      result = factory.readFromTextFile(input);

            input.Close();
            AssertTrue(result.ToString() == "f(a,g(b))");

//				Console.Out.WriteLine("result = " + result);
//			}
//			catch (FileNotFoundException e1)
//			{
//				Console.Out.WriteLine(e1);
//			}
//			catch (IOException e2)
//			{
//				Console.Out.WriteLine(e2);
//			}
        }
Example #3
0
        public virtual ATermList replace(ATerm el, int i)
        {
            int       lcv;
            ArrayList buffer;
            ATermList cur;

            if (0 > i || i > length)
            {
                throw new ArgumentException("illegal list index: " + i);
            }

            buffer = new ArrayList(i);

            cur = this;
            for (lcv = 0; lcv < i; lcv++)
            {
                buffer.Add(cur.getFirst());
                cur = cur.getNext();
            }

            /* Skip the old element */
            cur = cur.getNext();

            /* Add the new element */
            cur = cur.insert(el);

            /* Add the prefix */
            for (--lcv; lcv >= 0; lcv--)
            {
                cur = cur.insert((ATerm)buffer[lcv]);
            }

            return(cur);
        }
Example #4
0
		public virtual void initHashCode(ATermList annos, AFun fun, ATerm[] i_args) 
		{
			this.fun  = fun;
			this.args = i_args;
			this.internSetAnnotations(annos);
			this.setHashCode(this.hashFunction());
		}
Example #5
0
        private ATerm[] parseATermsArray(ATermReader reader)         // throws IOException
        {
            ArrayList list = new ArrayList();
            ATerm     term;

            term = parseFromReader(reader);
            list.Add(term);
            while (reader.getLastChar() == ',')
            {
                reader.readSkippingWS();
                term = parseFromReader(reader);
                list.Add(term);
            }

            ATerm[] array = new ATerm[list.Count];
            int     index = 0;

            foreach (Object o in list)
            {
                array[index++] = (ATerm)o;
            }

/*
 *          ListIterator iter = list.listIterator();
 *                      int index = 0;
 *                      while (iter.hasNext())
 *                      {
 *                              array[index++] = (ATerm) iter.next();
 *                      }
 */
            return(array);
        }
Example #6
0
        protected void testFileParser()
        {
            try
            {
                /*
                 * FileOutputStream output = new FileOutputStream("testFileParser.txt");
                 * String s = factory.parse("f(a,g(b))").toString();
                 * output.write(s);
                 * output.close();
                 */
                FileStream input  = new FileStream("testFileParser.txt", FileMode.Open);
                ATerm      result = factory.readFromTextFile(input);
                input.Close();

                Console.Out.WriteLine("result = " + result);
            }
            catch (FileNotFoundException e1)
            {
                Console.Out.WriteLine(e1);
            }
            catch (IOException e2)
            {
                Console.Out.WriteLine(e2);
            }
        }
Example #7
0
		internal override bool match(ATerm pattern, ArrayList list) 
		{
			if (this.equals(pattern)) 
			{
				return true;
			}

			if (pattern.getType() == ATermType.PLACEHOLDER) 
			{
				ATerm type = ((ATermPlaceholder) pattern).getPlaceholder();
				if (type.getType() == ATermType.APPL) 
				{
					ATermAppl appl = (ATermAppl) type;
					AFun afun = appl.getAFun();
					if (afun.getName().Equals("blob")
						&& afun.getArity() == 0
						&& !afun.isQuoted()) 
					{
						list.Add(data);
						return true;
					}
				}
			}
			return base.match(pattern, list);
		}
Example #8
0
        internal override bool match(ATerm pattern, ArrayList list)
        {
            if (this.equals(pattern))
            {
                return(true);
            }

            if (pattern.getType() == ATermType.PLACEHOLDER)
            {
                ATerm type = ((ATermPlaceholder)pattern).getPlaceholder();
                if (type.getType() == ATermType.APPL)
                {
                    ATermAppl appl = (ATermAppl)type;
                    AFun      afun = appl.getAFun();
                    if (afun.getName().Equals("blob") &&
                        afun.getArity() == 0 &&
                        !afun.isQuoted())
                    {
                        list.Add(data);
                        return(true);
                    }
                }
            }
            return(base.match(pattern, list));
        }
Example #9
0
        public virtual int indexOf(ATerm el, int start)
        {
            int       i;
            ATermList cur;

            if (start < 0)
            {
                start += length + 1;
            }

            if (start > length)
            {
                throw new ArgumentException("start (" + start + ") > length of list (" + length + ")");
            }

            cur = this;
            for (i = 0; i < start; i++)
            {
                cur = cur.getNext();
            }

            while (!cur.isEmpty() && cur.getFirst() != el)
            {
                cur = cur.getNext();
                ++i;
            }

            return(cur.isEmpty() ? -1 : i);
        }
Example #10
0
        public virtual ATerm setAnnotation(ATerm label, ATerm anno)
        {
            ATermList new_annos = annotations.dictPut(label, anno);
            ATerm     result    = setAnnotations(new_annos);

            return(result);
        }
Example #11
0
        public virtual int lastIndexOf(ATerm el, int start)
        {
            int result;

            if (start < 0)
            {
                start += length + 1;
            }

            if (start > length)
            {
                throw new ArgumentException("start (" + start + ") > length of list (" + length + ")");
            }

            if (start > 0)
            {
                result = next.lastIndexOf(el, start - 1);
                if (result >= 0)
                {
                    return(result + 1);
                }
            }

            if (first == el)
            {
                return(0);
            }
            else
            {
                return(-1);
            }
        }
Example #12
0
 public virtual ATermList makeList(ATerm first, ATermList next, ATermList annos)
 {
     lock (protoList)
     {
         protoList.initHashCode(annos, first, next);
         return((ATermList)build(protoList));
     }
 }
Example #13
0
 public virtual ATermPlaceholder makePlaceholder(ATerm type, ATermList annos)
 {
     lock (protoPlaceholder)
     {
         protoPlaceholder.init(hashPlaceholder(annos, type), annos, type);
         return((ATermPlaceholder)build(protoPlaceholder));
     }
 }
Example #14
0
 public virtual bool isEqual(ATerm term)
 {
     if (term is ATermImpl)
     {
         return(this == term);
     }
     return(factory.isDeepEqual(this, term));
 }
Example #15
0
 public override ATerm make(ArrayList args)
 {
     ATerm[] newargs = new ATerm[this.args.Length];
     for (int i = 0; i < this.args.Length; i++)
     {
         newargs[i] = this.args[i].make(args);
     }
     //return make(fun, newargs);
     return(getPureFactory().makeAppl(fun, newargs, getPureFactory().makeList()));
 }
Example #16
0
        static void Main(string[] args)
        {
            PureFactory        factory = new PureFactory();
            ATerm              t       = factory.parse("f(g(1,h(2,3)),i(4,5),j(6,k(7,[8,9])))");
            ATermLeavesCounter v       = new ATermLeavesCounter();
            TopDown            td      = new TopDown(v);

            td.visit(t);
            Console.Out.WriteLine(v.Count);
        }
Example #17
0
        internal override bool match(ATerm pattern, ArrayList list)
        {
            if (pattern.getType() == ATermType.APPL)
            {
                ATermAppl appl = (ATermAppl)pattern;
                if (fun.equals(appl.getAFun()))
                {
                    return(matchArguments(appl.getArgumentArray(), list));
                }
                else
                {
                    return(false);
                }
            }

            if (pattern.getType() == ATermType.PLACEHOLDER)
            {
                ATerm type = ((ATermPlaceholder)pattern).getPlaceholder();
                if (type.getType() == ATermType.APPL)
                {
                    ATermAppl appl = (ATermAppl)type;
                    AFun      afun = appl.getAFun();
                    if (afun.getName().Equals("appl") && !afun.isQuoted())
                    {
                        list.Add(fun.getName());
                        return(matchArguments(appl.getArgumentArray(), list));
                    }
                    else if (afun.getName().Equals("str") && !afun.isQuoted())
                    {
                        if (fun.isQuoted())
                        {
                            list.Add(fun.getName());
                            return(matchArguments(appl.getArgumentArray(), list));
                        }
                    }
                    else if (afun.getName().Equals("fun") && !afun.isQuoted())
                    {
                        if (!fun.isQuoted())
                        {
                            list.Add(fun.getName());
                            return(matchArguments(appl.getArgumentArray(), list));
                        }
                    }
                    else if (afun.getName().Equals("id") && !afun.isQuoted())
                    {
                        if (!fun.isQuoted())
                        {
                            list.Add(fun.getName());
                            return(matchArguments(appl.getArgumentArray(), list));
                        }
                    }
                }
            }
            return(base.match(pattern, list));
        }
Example #18
0
/*
 *      public final static void main(String[] args)
 *                                       {
 *                                               TestFibInterpreted t = new TestFibInterpreted(new PureFactory());
 *
 *                                               t.initRules();
 *                                               t.test1(5);
 *                                       }
 */

        public TestFibInterpreted(ATermFactory factory)
        {
            this.factory = factory;

            zero  = factory.makeAFun("zero", 0, false);
            suc   = factory.makeAFun("suc", 1, false);
            plus  = factory.makeAFun("plus", 2, false);
            fib   = factory.makeAFun("fib", 1, false);
            tzero = factory.makeAppl(zero);
            fail  = factory.parse("fail");
        }
Example #19
0
		internal virtual void init(int hashCode, ATermList annos, AFun fun, ATerm[] i_args) 
		{
			base.init(hashCode, annos);
			this.fun = fun;
			this.args = new ATerm[fun.getArity()];
    
			for(int i=0; i<fun.getArity(); i++) 
			{
				this.args[i] = i_args[i];
			}
		}
Example #20
0
/*
 * 		public final static void main(String[] args) 
					 {
						 TestFibInterpreted t = new TestFibInterpreted(new PureFactory());

						 t.initRules();
						 t.test1(5);
					 }
*/

		public TestFibInterpreted(ATermFactory factory) 
		{
			this.factory = factory;

			zero = factory.makeAFun("zero", 0, false);
			suc = factory.makeAFun("suc", 1, false);
			plus = factory.makeAFun("plus", 2, false);
			fib = factory.makeAFun("fib", 1, false);
			tzero = factory.makeAppl(zero);
			fail = factory.parse("fail");
		}
Example #21
0
        public virtual ATerm normalize(ATerm t)
        {
            ATerm s = t;

            do
            {
                t = s;
                s = oneStep(t);
            } while (!s.Equals(fail));
            return(t);
        }
 public override ATerm setSubTerm(int index, ATerm t)
 {
     if (index == 1)
     {
         return(setPlaceholder(t));
     }
     else
     {
         throw new Exception("no " + index + "-th child!");
     }
 }
Example #23
0
		protected override void SetUp()
		{
			base.SetUp();
			factory = Tester.theFactory;

			zero = factory.makeAFun("zero", 0, false);
			suc = factory.makeAFun("suc", 1, false);
			plus = factory.makeAFun("plus", 2, false);
			fib = factory.makeAFun("fib", 1, false);
			tzero = factory.makeAppl(zero);
			fail = factory.parse("fail");
		}
Example #24
0
        protected override void SetUp()
        {
            base.SetUp();
            factory = Tester.theFactory;

            zero  = factory.makeAFun("zero", 0, false);
            suc   = factory.makeAFun("suc", 1, false);
            plus  = factory.makeAFun("plus", 2, false);
            fib   = factory.makeAFun("fib", 1, false);
            tzero = factory.makeAppl(zero);
            fail  = factory.parse("fail");
        }
Example #25
0
        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));
        }
Example #26
0
        public void test1(int n)
        {
            ATermAppl N = tzero;

            for (int i = 0; i < n; i++)
            {
                N = factory.makeAppl(suc, N);
            }
            ATerm tfib = factory.makeAppl(fib, N);

            normalize(tfib);
        }
Example #27
0
		public virtual void TestParser() 
		{
			factory = Tester.theFactory;

			ATerm[] T = new ATerm[20];
			int index = 0;
    
			T[index++] = factory.parse("g");
			T[index++] = factory.parse("f()");
			T[index++] = factory.parse("f(1)");
			T[index++] = factory.parse("f(1,2)");
			T[index++] = factory.parse("f(1,2,<int>)");
			T[index++] = factory.parse("[]");
			T[index++] = factory.parse("[1]");
			T[index++] = factory.parse("[1,2]");
			T[index++] = factory.parse("<x>");
			T[index++] = factory.parse("3.14");
			T[index++] = factory.parse("[1,3.5,4e6,123.21E-3,-12]");
			T[index++] = factory.parse("f(\"x y z\"(),<abc(31)>,[])");
			T[index++] = factory.parse("home([<name(\"\",string)>,<phone(\"\",PhoneNumber)>])");
			T[index++] = factory.parse("[ a , b]");
			T[index++] = factory.parse("f(a){[x,y],[1,2]}");
			T[index++] = factory.parse("[(),(a)]");
			T[index++] = factory.parse("[1,a,f(1)]");
			T[index++] = factory.parse("[1,\"a\",f(1), \"g\"(a,\"b\")]");

			index = 0;
			AssertTrue(T[index++].ToString() == "g");
 			AssertTrue(T[index++].ToString() == "f");
			AssertTrue(T[index++].ToString() == "f(1)");
			AssertTrue(T[index++].ToString() == "f(1,2)");
			AssertTrue(T[index++].ToString() == "f(1,2,<int>)");
			AssertTrue(T[index++].ToString() == "[]");
			AssertTrue(T[index++].ToString() == "[1]");
			AssertTrue(T[index++].ToString() == "[1,2]");
			AssertTrue(T[index++].ToString() == "<x>");
			AssertTrue(T[index++].ToString() == "3.14");
			AssertTrue(T[index++].ToString() == "[1,3.5,4000000,0.12321,-12]");
			AssertTrue(T[index++].ToString() == "f(\"x y z\",<abc(31)>,[])");
			AssertTrue(T[index++].ToString() == "home([<name(\"\",string)>,<phone(\"\",PhoneNumber)>])");
			AssertTrue(T[index++].ToString() == "[a,b]");
			AssertTrue(T[index++].ToString() == "f(a){[x,y],[1,2]}");
			AssertTrue(T[index++].ToString() == "[(),(a)]");
			AssertTrue(T[index++].ToString() == "[1,a,f(1)]");
			AssertTrue(T[index++].ToString() == "[1,\"a\",f(1),\"g\"(a,\"b\")]");

			//			for(int i=0; i<index; i++) 
//			{
//				Console.Out.WriteLine("term " + i + ": " + T[i]);
//			}
    
		}
Example #28
0
 public virtual ATermAppl makeAppl(
     AFun fun,
     ATerm arg1,
     ATerm arg2,
     ATerm arg3,
     ATerm arg4,
     ATerm arg5,
     ATerm arg6,
     ATerm arg7)
 {
     ATerm[] args = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
     return(makeAppl(fun, args));
 }
Example #29
0
        public virtual ArrayList match(ATerm pattern)
        {
            ArrayList list = new ArrayList();

            if (match(pattern, list))
            {
                return(list);
            }
            else
            {
                return(null);
            }
        }
Example #30
0
        public virtual void TestFibInterpreted(int n)
        {
            initRules();
            ATermAppl N = tzero;

            for (int i = 0; i < n; i++)
            {
                N = factory.makeAppl(suc, N);
            }
            ATerm tfib = factory.makeAppl(fib, N);

            normalize(tfib);
        }
Example #31
0
        public virtual void TestParser()
        {
            factory = Tester.theFactory;

            ATerm[] T     = new ATerm[20];
            int     index = 0;

            T[index++] = factory.parse("g");
            T[index++] = factory.parse("f()");
            T[index++] = factory.parse("f(1)");
            T[index++] = factory.parse("f(1,2)");
            T[index++] = factory.parse("f(1,2,<int>)");
            T[index++] = factory.parse("[]");
            T[index++] = factory.parse("[1]");
            T[index++] = factory.parse("[1,2]");
            T[index++] = factory.parse("<x>");
            T[index++] = factory.parse("3.14");
            T[index++] = factory.parse("[1,3.5,4e6,123.21E-3,-12]");
            T[index++] = factory.parse("f(\"x y z\"(),<abc(31)>,[])");
            T[index++] = factory.parse("home([<name(\"\",string)>,<phone(\"\",PhoneNumber)>])");
            T[index++] = factory.parse("[ a , b]");
            T[index++] = factory.parse("f(a){[x,y],[1,2]}");
            T[index++] = factory.parse("[(),(a)]");
            T[index++] = factory.parse("[1,a,f(1)]");
            T[index++] = factory.parse("[1,\"a\",f(1), \"g\"(a,\"b\")]");

            index = 0;
            AssertTrue(T[index++].ToString() == "g");
            AssertTrue(T[index++].ToString() == "f");
            AssertTrue(T[index++].ToString() == "f(1)");
            AssertTrue(T[index++].ToString() == "f(1,2)");
            AssertTrue(T[index++].ToString() == "f(1,2,<int>)");
            AssertTrue(T[index++].ToString() == "[]");
            AssertTrue(T[index++].ToString() == "[1]");
            AssertTrue(T[index++].ToString() == "[1,2]");
            AssertTrue(T[index++].ToString() == "<x>");
            AssertTrue(T[index++].ToString() == "3.14");
            AssertTrue(T[index++].ToString() == "[1,3.5,4000000,0.12321,-12]");
            AssertTrue(T[index++].ToString() == "f(\"x y z\",<abc(31)>,[])");
            AssertTrue(T[index++].ToString() == "home([<name(\"\",string)>,<phone(\"\",PhoneNumber)>])");
            AssertTrue(T[index++].ToString() == "[a,b]");
            AssertTrue(T[index++].ToString() == "f(a){[x,y],[1,2]}");
            AssertTrue(T[index++].ToString() == "[(),(a)]");
            AssertTrue(T[index++].ToString() == "[1,a,f(1)]");
            AssertTrue(T[index++].ToString() == "[1,\"a\",f(1),\"g\"(a,\"b\")]");

            //			for(int i=0; i<index; i++)
//			{
//				Console.Out.WriteLine("term " + i + ": " + T[i]);
//			}
        }
Example #32
0
 public virtual ATerm parse(string trm)
 {
     try
     {
         ATermReader reader = new ATermReader(new StringReader(trm));
         reader.readSkippingWS();
         ATerm result = parseFromReader(reader);
         return(result);
     }
     catch (IOException)
     {
         throw new ParseError("premature end of string");
     }
 }
Example #33
0
        public virtual ATermList insertAt(ATerm el, int i)
        {
            if (0 > i || i > length)
            {
                throw new ArgumentException("illegal list index: " + i);
            }

            if (i == 0)
            {
                return(insert(el));
            }

            return(next.insertAt(el, i - 1).insert(first));
        }
Example #34
0
        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));
        }
Example #35
0
		/**
		 * init is used internally by the PureFactory to initialize a prototype of
		 * an ATermList without using the new operator all the time
		 * 
		 */
		public virtual void init(int hashCode, ATermList annos, ATerm first, ATermList next) 
		{
			base.init(hashCode, annos);
			this.first = first;
			this.next = next;

			if (first == null && next == null) 
			{
				this.length = 0;
			}
			else 
			{
				this.length = 1 + next.getLength();
			}
		}
Example #36
0
        /**
         * init is used internally by the PureFactory to initialize a prototype of
         * an ATermList without using the new operator all the time
         *
         */
        public virtual void init(int hashCode, ATermList annos, ATerm first, ATermList next)
        {
            base.init(hashCode, annos);
            this.first = first;
            this.next  = next;

            if (first == null && next == null)
            {
                this.length = 0;
            }
            else
            {
                this.length = 1 + next.getLength();
            }
        }
Example #37
0
        public virtual void TestMatch()
        {
            factory = Tester.theFactory;

            ATerm     t      = factory.parse("node(\"Pico-eval\",box,182,21,62,26)");
            ArrayList result = t.match("node(<str>,<fun>,<int>,<int>,<int>,<int>)");

            AssertTrue(result != null);

            t      = factory.parse("f(1,2,3)");
            result = t.match("f(1,2,3)");
            AssertTrue(result != null);

//			Console.Out.WriteLine("pass: testMatch");
        }
Example #38
0
		public virtual void initHashCode(ATermList annos, ATerm first, ATermList next) 
		{
			this.first = first;
			this.next = next;
			this.internSetAnnotations(annos);
			this.setHashCode(this.hashFunction());
			//super.init(hashCode, annos);

			if (first == null && next == null) 
			{
				this.length = 0;
			}
			else 
			{
				this.length = 1 + next.getLength();
			}
		}
Example #39
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm arg1, ATerm arg2, ATerm arg3, ATerm arg4) 
		{
			ATerm[] argarray4 = new ATerm[] { arg1, arg2, arg3, arg4 };
			return makeAppl(fun, argarray4);
		}
Example #40
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm arg1, ATerm arg2, ATerm arg3, ATerm arg4, ATerm arg5) 
		{
			ATerm[] argarray5 = new ATerm[] { arg1, arg2, arg3, arg4, arg5 };
			return makeAppl(fun, argarray5);
		}
Example #41
0
		public virtual ATermAppl makeAppl(
			AFun fun,
			ATerm arg1,
			ATerm arg2,
			ATerm arg3,
			ATerm arg4,
			ATerm arg5,
			ATerm arg6,
			ATerm arg7) 
		{
			ATerm[] args = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
			return makeAppl(fun, args);
		}
		   public virtual ATerm setPlaceholder(ATerm newtype) 
		   {
			   return getPureFactory().makePlaceholder(newtype, getAnnotations());
		   }
Example #43
0
		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);
		}
Example #44
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm arg1, ATerm arg2) 
		{
			ATerm[] argarray2 = new ATerm[] { arg1, arg2 };
			return makeAppl(fun, argarray2);
		}
Example #45
0
		public ATerm oneStep(ATerm subject) 
		{
			int ruleNumber = 0;
			ArrayList list;

			// fib(zero) -> suc(zero)
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				return rhs[ruleNumber];
			}
			ruleNumber++;

			// fib(suc(zero)) -> suc(zero)
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				return rhs[ruleNumber];
			}
			ruleNumber++;

			// fib(suc(suc(X))) -> plus(fib(X),fib(suc(X)))
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				ATerm X = (ATerm) list[0];
				list.Add(X);
				return factory.make(rhs[ruleNumber], list);
			}
			ruleNumber++;

			// plus(zero,X) -> X
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				return factory.make(rhs[ruleNumber], list);
			}
			ruleNumber++;

			// plus(suc(X),Y) -> plus(X,suc(Y))
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				return factory.make(rhs[ruleNumber], list);
			}
			ruleNumber++;

			// congruence (suc)
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				//System.out.println("congsuc"); // applied 1184122 times fir fib(14)
				ATerm X = (ATerm) list[0];
				ATerm Xp = oneStep(X);
				if (Xp.equals(fail)) 
				{
					return fail;
				} 
				else 
				{
					list.Clear();
					list.Add(Xp);
					return factory.make(rhs[ruleNumber], list);
				}
			}
			ruleNumber++;

			// congruence (plus)
			list = subject.match(lhs[ruleNumber]);
			if (list != null) 
			{
				//System.out.println("congplus"); // applied 9159 times fir fib(14)
				ATerm X = (ATerm) list[0];
				ATerm Xp = oneStep(X);
				if (Xp.Equals(fail)) 
				{
					ATerm Y = (ATerm) list[1];
					ATerm Yp = oneStep(Y);
					if (Yp.Equals(fail)) 
					{
						return fail;
					} 
					else 
					{
						list.Clear();
						list.Add(X);
						list.Add(Yp);
						return factory.make(rhs[ruleNumber], list);
					}
				} 
				else 
				{
					ATerm Y = (ATerm) list[1];
					list.Clear();
					list.Add(Xp);
					list.Add(Y);
					return factory.make(rhs[ruleNumber], list);
				}
			}
			ruleNumber++;

			return fail;
		}
Example #46
0
		public ATerm normalize(ATerm t) 
		{
			ATerm s = t;
			do 
			{
				t = s;
				s = oneStep(t);
			} while (!s.Equals(fail));
			return t;
		}
Example #47
0
		abstract public ATerm setSubTerm(int index, ATerm t);
Example #48
0
		public ATerm oneStepInnermost(ATerm subject) 
		{
			ArrayList list;

			// fib(zero) -> suc(zero)
			list = subject.match(lhs[0]);
			if (list != null) 
			{
				return rhs[0];
			}

			// fib(suc(zero)) -> suc(zero)
			list = subject.match(lhs[1]);
			if (list != null) 
			{
				return rhs[1];
			}

			// fib(suc(suc(X))) -> plus(fib(X),fib(suc(X)))
			list = subject.match(lhs[2]);
			if (list != null) 
			{
				ATerm X = (ATerm) list[0];
				ATerm X1 = normalize(factory.makeAppl(fib, X));
				ATerm X2 = normalize(factory.makeAppl(fib, factory.makeAppl(suc, X)));
				return factory.makeAppl(plus, X1, X2);
			}

			// plus(zero,X) -> X
			list = subject.match(lhs[3]);
			if (list != null) 
			{
				return (ATerm) list[0];
			}

			// plus(suc(X),Y) -> plus(X,suc(Y)))
			list = subject.match(lhs[4]);
			if (list != null) 
			{
				return factory.make(rhs[4], list);
			}

			return fail;
		}
		   public virtual void init(int hashCode, ATermList annos, ATerm type) 
		   {
			   base.init(hashCode, annos);
			   this.type = type;
		   }
		   public override ATerm setSubTerm(int index, ATerm t) 
		   {
			   if (index == 1) 
			   {
				   return setPlaceholder(t);
			   } 
			   else 
			   {
				   throw new Exception("no " + index + "-th child!");
			   }
		   }
Example #51
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm arg1, ATerm arg2, ATerm arg3) 
		{
			ATerm[] argarray3 = new ATerm[] { arg1, arg2, arg3 };
			return makeAppl(fun, argarray3);
		}
Example #52
0
		public virtual void storeNextTerm(ATerm t, int size) 
		{
			if (table == null) 
			{
				return;
			}

			if (size <= PureFactory.abbrevSize(nr_terms)) 
			{
				return;
			}

			if (nr_terms == table.Length) 
			{
				ATerm[] new_table = new ATerm[table.Length + TABLE_INCREMENT];
				Array.Copy(table, 0, new_table, 0, table.Length);
				table = new_table;
			}

			table[nr_terms++] = t;
		}
Example #53
0
		public virtual void TestPatternMatch() 
		{
			factory = Tester.theFactory;
			ATerm[] T = new ATerm[10];
			ArrayList result;
			ATerm empty = factory.makeList();
    
			T[0] = factory.parse("f(1,2,3)"); 
			T[1] = factory.parse("[1,2,3]"); 
			T[2] = factory.parse("f(a,\"abc\",2.3,<abc>)"); 
			T[3] = factory.parse("f(a,[])"); 

			AssertTrue("match-1a",T[0].match("f(1,2,3)") != null);

			result = T[1].match("<term>");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-1b",result != null && result[0].Equals(T[1]) );

    
			result = T[1].match("[<list>]");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-1c",result != null && result[0].Equals(T[1]) );

    
			result = T[1].match("[<int>,<list>]");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-1d",result != null &&
				result[0].Equals(1) &&
				result[1].Equals(factory.parse("[2,3]")) );
    
			//result = T[1].match("[<list>,2,<int>]");
			//Console.Out.WriteLine("result = " + result);

    
			result = factory.parse("f(a)").match("f(<term>)");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-2a",result != null &&
				result[0].Equals(factory.parse("a")) );
    
			result = factory.parse("f(a)").match("<term>");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-2b",result != null &&
				result[0].Equals(factory.parse("f(a)")) );
    
			result = factory.parse("f(a)").match("<fun(<term>)>");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-2c",result != null &&
				result[0].Equals("f") &&
				result[1].Equals(factory.parse("a")) );

			result = factory.parse("a").match("<fun>");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-2d",result != null &&
				result[0].Equals("a") );

			//result = factory.parse("f(<abc>)").match("f(<placeholder>)");
			//Console.Out.WriteLine("result = " + result);
			//test(result != null &&
			// result.get(0).Equals(factory.parse("<abc>")), "match-2e");
    
			result = T[0].match("f(1,<int>,3)"); 
			AssertTrue("match-3",result != null && result.Count == 1 &&  
				result[0].Equals(2) );
    
			result = T[2].match("f(<term>,<term>,<real>,<placeholder>)"); 
			//Console.Out.WriteLine("result = " + result); 
			AssertTrue("match-4a",result != null && result.Count == 4 );

			AssertTrue("match-4b",result[0].Equals(factory.parse("a")) );
			AssertTrue("match-4c",result[1].Equals(factory.parse("\"abc\"")) ); 
			AssertTrue("match-4d",result[2].Equals(2.3) ); 
			//test(result.get(3).Equals(factory.parse("<abc>")), "match-4e"); 

			result = T[1].match("[<list>]") ;
			AssertTrue("match-6a",result != null && result.Count == 1 &&  
				result[0].Equals(T[1]) ); 
    
			result = T[1].match("[<int>,<list>]"); 
			AssertTrue("match-6b",result != null && result.Count == 2 &&  
				result[0].Equals(1) ); 
			AssertTrue("match-6c",result[1].Equals((ATermList)factory.parse("[2,3]")));

			result = empty.match("[]");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-6d",result!=null && result.Count==0 );

			result = empty.match("[<list>]");
			//Console.Out.WriteLine("result = " + result);
			AssertTrue("match-6e",result[0].Equals((ATermList)factory.parse("[]")));
    
			result = T[0].match("<fun(<int>,<list>)>");
			AssertTrue("match-7a",result != null && result.Count == 3 ); 
			AssertTrue("match-7b",result[0].Equals("f") ); 
			AssertTrue("match-7c",result[1].Equals(1) ); 
			AssertTrue("match-7d",result[2].Equals((ATermList)factory.parse("[2,3]"))); 

			result = T[3].match("f(<term>,[<list>])");
			AssertTrue("match-8a",result != null && result.Count == 2 ); 
			AssertTrue("match-8b",result[0].Equals((ATerm)factory.parse("a")) ); 
			AssertTrue("match-8c",result[1] != null ); 
			AssertTrue("match-8d",((ATermList)((ArrayList)result)[1]).getLength()==0 ); 

			/*
		  result = T[0].match("<f>"); 
		  Console.Out.WriteLine("result = " + result);  
		  test(result != null && result.size()==1 &&  
			   result.get(0).Equals(T[0]), "match-8"); 
    
		  result = T[0].match("<f(1,2,<int>)>");
		  Console.Out.WriteLine("result = " + result);  
		  test(result != null && result.size() == 2, "match-9a"); 
		  test(result.get(0).Equals(T[0]), "match9b");  
		  test(result.get(1).Equals(new Integer(3)), "match-9b");
			*/

			result = factory.parse("fib(suc(suc(suc(suc(suc(suc(suc(suc(suc(suc(zero())))))))))))").match("fib(suc(<term()>))"); 
			//Console.Out.WriteLine("result = " + result); 

//			Console.Out.WriteLine("pass: testPatternMatch");
		}
Example #54
0
		public virtual ATerm importTerm(ATerm term) 
		{
			throw new Exception("not yet implemented!");
		}
Example #55
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm arg) 
		{
			ATerm[] argarray1 = new ATerm[] { arg };
			return makeAppl(fun, argarray1);
		}
Example #56
0
		public virtual ATerm make(ATerm pattern, ArrayList args) 
		{
			return pattern.make(args);
		}
Example #57
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm[] args, ATermList annos) 
		{
			lock (protoAppl) 
			{
				protoAppl.initHashCode(annos, fun, args);
				return (ATermAppl) build(protoAppl);
			}
		}
Example #58
0
		private ATerm[] parseATermsArray(ATermReader reader) // throws IOException 
		{
			ArrayList list = new ArrayList();
			ATerm term;

			term = parseFromReader(reader);
			list.Add(term);
			while (reader.getLastChar() == ',') 
			{
				reader.readSkippingWS();
				term = parseFromReader(reader);
				list.Add(term);
			}

			ATerm[] array = new ATerm[list.Count];
			int index = 0;
			foreach(Object o in list)
			{
				array[index++] = (ATerm)o;
			}
/*
 * 			ListIterator iter = list.listIterator();
			int index = 0;
			while (iter.hasNext()) 
			{
				array[index++] = (ATerm) iter.next();
			}
*/
			return array;
		}
Example #59
0
		public virtual bool isDeepEqual(ATermImpl t1, ATerm t2) 
		{
			throw new MissingMemberException("not yet implemented!");
		}
Example #60
0
		public virtual void testMaxTerm() 
		{
			factory = Tester.theFactory;
			AFun f = factory.makeAFun("f", 1, false);
			AFun a = factory.makeAFun("a", 0, false);

			int size = 500;
			ATerm[] array1 = new ATerm[size];
			ATerm[] array2 = new ATerm[size];

			long start   = DateTime.Now.Ticks;
//			Console.Out.WriteLine("array1");
			for(int i=0 ; i<size ; i++) 
			{
//				if(i%100 == 0) 
//				{
//					Console.Out.Write(i + "  ");
//				}

				int idx = i%10;
				array1[idx] = factory.makeAppl(a);
				for(int j=0 ; j<2*i ; j++) 
				{
					array1[idx] = factory.makeAppl(f,array1[idx]);
				}
				//Console.Out.WriteLine("array[" + i + "] = " + array[i]);
			}

//			Console.Out.WriteLine("\narray2");
			for(int i=0 ; i<size ; i++) 
			{
//				if(i%100 == 0) 
//				{
//					Console.Out.Write(i + "  ");
//				}

				int idx = i%10;
				array2[idx] = factory.makeAppl(a);
				for(int j=0 ; j<2*i ; j++) 
				{
					array2[idx] = factory.makeAppl(f,array2[idx]);
				}
				//Console.Out.WriteLine("array[" + i + "] = " + array[i]);
			}

//			Console.Out.WriteLine("\ntest");
			for(int i=0 ; i<size ; i++) 
			{
				if(i%500 == 0) 
				{
//					Console.Out.Write(i + "  ");
				}

				int idx = i%10;
				if(array1[idx] != array2[idx]) 
				{
//					Console.Out.WriteLine("array1[" + idx + "] = " + array1[idx]);
//					Console.Out.WriteLine("array2[" + idx + "] = " + array2[idx]);
					throw new Exception("i = " + idx);
				}
			}
			long end     = DateTime.Now.Ticks;

//			Console.Out.WriteLine("\ntest " + size + " ok in " + (end-start) + " ms");
//			Console.Out.WriteLine(factory);
		}