コード例 #1
0
        public virtual ATerm normalize(ATerm t)
        {
            ATerm s = t;

            do
            {
                t = s;
                s = oneStep(t);
            } while (!s.Equals(fail));
            return(t);
        }
コード例 #2
0
ファイル: FilesTest.cs プロジェクト: scrasmussen/aterms
        public virtual void testFiles()        // throws IOException
        {
            factory = Tester.theFactory;
            ATerm t1 = factory.readFromFile(srcdir + "/test.trm");
//			Console.Out.WriteLine("done reading test.trm");
            ATerm t2 = factory.readFromFile(srcdir + "/test.taf");
//			Console.Out.WriteLine("done reading test.taf");

            StreamWriter stream = new StreamWriter(new FileStream("test.trm2", FileMode.OpenOrCreate));

            t1.writeToTextFile(stream.BaseStream);
            stream.WriteLine();
            stream.Close();
//			Console.Out.WriteLine("done writing test.trm2");

            stream = new StreamWriter(new FileStream("test.taf2", FileMode.OpenOrCreate));
            t1.writeToSharedTextFile(stream.BaseStream);
            stream.Close();
//			Console.Out.WriteLine("done writing test.taf2");

            AssertTrue(t1.Equals(t2));
        }
コード例 #3
0
        public virtual 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);
        }