Ejemplo n.º 1
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);
		}
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 public ATermBlobImpl(PureFactory factory) : base(factory)
 {
 }
Ejemplo n.º 5
0
 public AFunImpl(PureFactory factory) : base(factory)
 {
 }
Ejemplo n.º 6
0
		   public ATermPlaceholderImpl(PureFactory factory) : base(factory)
		   {
		   }
Ejemplo n.º 7
0
		public ATermBlobImpl(PureFactory factory) : base(factory)
		{
		}
Ejemplo n.º 8
0
 public ATermApplImpl(PureFactory factory) : base(factory)
 {
 }
Ejemplo n.º 9
0
		public ATermListImpl(PureFactory factory) : base(factory)
		{
		}
Ejemplo n.º 10
0
 public ATermPlaceholderImpl(PureFactory factory) : base(factory)
 {
 }
Ejemplo n.º 11
0
		public ATermApplImpl(PureFactory factory): base(factory)
		{
		}
Ejemplo n.º 12
0
		public AFunImpl(PureFactory factory) : base(factory)
		{
		}
Ejemplo n.º 13
0
		public ATermRealImpl(PureFactory factory) : base(factory)
		{
		}
Ejemplo n.º 14
0
        public override ATerm make(ArrayList args)
        {
            PureFactory factory = getPureFactory();
            ATermAppl   appl;
            AFun        fun;
            string      name;

            appl = (ATermAppl)type;
            fun  = appl.getAFun();
            name = fun.getName();
            if (!fun.isQuoted())
            {
                if (fun.getArity() == 0)
                {
                    if (name.Equals("term"))
                    {
                        ATerm t = (ATerm)args[0];
                        args.RemoveAt(0);

                        return(t);
                    }
                    else if (name.Equals("list"))
                    {
                        ATermList l = (ATermList)args[0];
                        args.RemoveAt(0);

                        return(l);
                    }
                    else if (name.Equals("bool"))
                    {
                        bool b = (bool)args[0];
                        args.RemoveAt(0);

                        return(factory.makeAppl(factory.makeAFun(b.ToString(), 0, false)));
                    }
                    else if (name.Equals("int"))
                    {
                        int i = (int)args[0];
                        args.RemoveAt(0);

                        return(factory.makeInt(i));
                    }
                    else if (name.Equals("real"))
                    {
                        double d = (double)args[0];
                        args.RemoveAt(0);

                        return(factory.makeReal(d));
                    }
                    else if (name.Equals("placeholder"))
                    {
                        ATerm atype = (ATerm)args[0];
                        args.RemoveAt(0);
                        return(factory.makePlaceholder(atype));
                    }
                    else if (name.Equals("str"))
                    {
                        string str = (string)args[0];
                        args.RemoveAt(0);
                        return(factory.makeAppl(factory.makeAFun(str, 0, true)));
                    }
                    else if (name.Equals("id"))
                    {
                        string str = (string)args[0];
                        args.RemoveAt(0);
                        return(factory.makeAppl(factory.makeAFun(str, 0, false)));
                    }
                    else if (name.Equals("fun"))
                    {
                        string str = (string)args[0];
                        args.RemoveAt(0);
                        return(factory.makeAppl(factory.makeAFun(str, 0, false)));
                    }
                }
                if (name.Equals("appl"))
                {
                    ATermList oldargs = appl.getArguments();
                    string    newname = (string)args[0];
                    args.RemoveAt(0);
                    ATermList newargs = (ATermList)oldargs.make(args);
                    AFun      newfun  = factory.makeAFun(newname, newargs.getLength(), false);
                    return(factory.makeApplList(newfun, newargs));
                }
            }
            throw new Exception("illegal pattern: " + this);
        }
Ejemplo n.º 15
0
 internal ATermImpl(PureFactory factory) : base()
 {
     this.factory = factory;
 }
Ejemplo n.º 16
0
 public ATermListImpl(PureFactory factory) : base(factory)
 {
 }
Ejemplo n.º 17
0
 public ATermRealImpl(PureFactory factory) : base(factory)
 {
 }