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); }
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 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; }
public ATermBlobImpl(PureFactory factory) : base(factory) { }
public AFunImpl(PureFactory factory) : base(factory) { }
public ATermPlaceholderImpl(PureFactory factory) : base(factory) { }
public ATermApplImpl(PureFactory factory) : base(factory) { }
public ATermListImpl(PureFactory factory) : base(factory) { }
public ATermApplImpl(PureFactory factory): base(factory) { }
public ATermRealImpl(PureFactory factory) : base(factory) { }
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); }
internal ATermImpl(PureFactory factory) : base() { this.factory = factory; }