public void InnerLoop(List <Argument> arguments, SubstitutionMap subMap) { foreach (var arg in arguments) { switch (arg.Type) { case ArgType.Constant: continue; case ArgType.Variable: if (subMap.ContainsKey(arg)) { var otherArg = subMap.Get(arg); arg.Name = otherArg.Name; arg.Type = otherArg.Type; if (otherArg.Arguments != null && otherArg.Arguments.Count > 0) { arg.Arguments = new List <Argument>(otherArg.Arguments); } } continue; case ArgType.Function: if (subMap.ContainsKey(arg)) { var otherArg = new Argument(subMap.Get(arg)); arg.Name = otherArg.Name; arg.Type = otherArg.Type; arg.Arguments = new List <Argument>(otherArg.Arguments); } else { InnerLoop(arg.Arguments, subMap); } continue; } } }
public SubstitutionMap(SubstitutionMap subMap) { if (subMap._vars.Count > 0) { _vars = new Dictionary <Argument, Argument>(); foreach (var key in subMap.Keys) { _vars.Add(new Argument(key), new Argument(subMap.Get(key))); } } else { _vars = new Dictionary <Argument, Argument>(); } }
public bool EqualTo(SubstitutionMap subMap) { if (Keys.Count() != subMap.Keys.Count()) { return(false); } foreach (var mySubs in _vars) { if (!subMap.ContainsKey(mySubs.Key)) { return(false); } if (!subMap.Get(mySubs.Key).EqualTo(Get(mySubs.Key))) { return(false); } } return(true); }
private static SubstitutionMap UnifySubMap(SubstitutionMap subMapA, SubstitutionMap subMapB) { var output = new SubstitutionMap(); foreach (var keyA in subMapA.Keys) { if (subMapB.ContainsKey(keyA)) { output.Failure = true; return(output); } output.Add(keyA, subMapA.Get(keyA)); } foreach (var keyB in subMapB.Keys) { output.Add(keyB, subMapB.Get(keyB)); } return(output); }