public InterpreterType(TrsTypeDefinitionTermBase sourceTypeDefinition, InterpreterType parentNode = null) { this.ParentNode = parentNode; this.CurrentNode = sourceTypeDefinition; if (sourceTypeDefinition is TrsTypeDefinitionTerm) ArgumentMatchedTypes.AddRange(((TrsTypeDefinitionTerm)sourceTypeDefinition).ArgumentTypes.Select(arg => new InterpreterType(arg,this))); else if (sourceTypeDefinition is TrsTypeDefinitionAcTerm) AcArgumentMatchedTypes = ((TrsTypeDefinitionAcTerm)sourceTypeDefinition).OnfArgumentTypes.ToDictionary(arg => new InterpreterType(arg.Term), arg => arg.Cardinality); }
public InterpreterType(TrsTypeDefinitionTermBase sourceTypeDefinition, InterpreterType parentNode = null) { this.ParentNode = parentNode; this.CurrentNode = sourceTypeDefinition; if (sourceTypeDefinition is TrsTypeDefinitionTerm) { ArgumentMatchedTypes.AddRange(((TrsTypeDefinitionTerm)sourceTypeDefinition).ArgumentTypes.Select(arg => new InterpreterType(arg, this))); } else if (sourceTypeDefinition is TrsTypeDefinitionAcTerm) { AcArgumentMatchedTypes = ((TrsTypeDefinitionAcTerm)sourceTypeDefinition).OnfArgumentTypes.ToDictionary(arg => new InterpreterType(arg.Term), arg => arg.Cardinality); } }
/// <summary> /// Uses the input type definitions as a bottom up tree automaton to /// test the input mapping of a variable to a term. /// /// Note: /// * All final states must be matched for a mapping to be valid. /// * Types are "merged" therefore the same type definition name can have multiple definitions associated. /// </summary> public bool IsSubstitutionValid(Substitution substitution) { HashSet <TrsTypeDefinitionTypeName> endStates = null; // If variable not bound, it is valid by default if (!typeMappings.TryGetValue(substitution.Variable, out endStates)) { return(true); } // Initial and final states var termIn = substitution.SubstitutionTerm.Convert(); AddDynamicStates(termIn); InterpreterType testType = new InterpreterType(termIn); var retVal = testType.IsTermValid(transitionFunction, endStates); // Undo dynamic changes to state machine to cater for $TrsNumber, $TrsConstant, $TrsString and $TrsVariable RemoveDynamicStates(); return(retVal); }
/// <summary> /// Uses the input type definitions as a bottom up tree automaton to /// test the input mapping of a variable to a term. /// /// Note: /// * All final states must be matched for a mapping to be valid. /// * Types are "merged" therefore the same type definition name can have multiple definitions associated. /// </summary> public bool IsSubstitutionValid(Substitution substitution) { HashSet<TrsTypeDefinitionTypeName> endStates = null; // If variable not bound, it is valid by default if (!typeMappings.TryGetValue(substitution.Variable, out endStates)) return true; // Initial and final states var termIn = substitution.SubstitutionTerm.Convert(); AddDynamicStates(termIn); InterpreterType testType = new InterpreterType(termIn); var retVal = testType.IsTermValid(transitionFunction, endStates); // Undo dynamic changes to state machine to cater for $TrsNumber, $TrsConstant, $TrsString and $TrsVariable RemoveDynamicStates(); return retVal; }