/// <summary> /// Erstellt einen Baumknoten aus einem Token. /// </summary> /// <param name="t">Der Token</param> /// <param name="stack">Stack mit bereits konvertierten Baumknoten</param> /// <param name="environment">Die Umgebung, in dessen Kontext der mathematische Term seine Gültigkeit besitzt.</param> /// <returns>Ein neuer Baumknoten.</returns> private static Node GenerateNodeFromToken(Token t, Stack <Node> stack, MathEnvironment environment) { NodeTemplate template = GetTemplateFromToken(t); if (template == null) { throw new NotImplementedException( $"There is no node knowledge for the token {t.Value} inside the knowledge base."); } if (template.ChildrenCount > stack.Count) { throw new ArgumentException( $"The stack does not contain enough nodes to create a new node of type {t.Type} with " + $"the value {t.Value}. The knowledge base may have not enough information for a function " + $"to parse it properly, or the term is malformed."); } Node[] arrChildNodes = new Node[template.ChildrenCount]; for (int i = arrChildNodes.Length - 1; i >= 0; i--) { arrChildNodes[i] = stack.Pop(); } return(new FactoryNode(template.Type, t.Value, environment, arrChildNodes));//, template.TransformationRules); }
private Node(Node template, Node[] arrChildNodes) { Type = template.Type; Value = template.Value; Environment = template.Environment; _arrChildNodes = arrChildNodes; //_arrTransformationRules = template._arrTransformationRules; _setTransformations = null; }
private protected Node(TokenType type, string strValue, MathEnvironment environment, Node[] arrChildNodes) //, TransformationRule[] arrTransformationRules) { Type = type; Value = strValue; Environment = environment; _arrChildNodes = arrChildNodes; //_arrTransformationRules = arrTransformationRules; _setTransformations = null; }
private Node(Node template) { _arrChildNodes = new Node[template._arrChildNodes.Length]; for (int i = 0; i < _arrChildNodes.Length; i++) { _arrChildNodes[i] = new Node(template._arrChildNodes[i]); } Type = template.Type; Value = template.Value; Environment = template.Environment; //_arrTransformationRules = template._arrTransformationRules; _setTransformations = template._setTransformations; }
/// <summary> /// Erstellt eine Baumstruktur, die einen mathematischen Term repräsentiert. /// </summary> /// <param name="token">Eine Liste an Token, die den mathematischen Term abbilden.</param> /// <param name="environment">Die Umgebung, in dessen Kontext der mathematische Term seine Gültigkeit besitzt.</param> /// <param name="bInfix">true, wenn der Term in der Infix-Notation formatiert ist, ansonsten false.</param> /// <returns>Eine Baumstruktur, die einen mathematischen Term repräsentiert.</returns> public static Node Get(IEnumerable <Token> token, MathEnvironment environment, bool bInfix) { if (bInfix) { token = ShuntingYardParser.InfixToRpn(token); } Stack <Node> stack = new Stack <Node>(); foreach (Token t in token) { stack.Push(GenerateNodeFromToken(t, stack, environment)); } if (stack.Count != 1) { throw new ArithmeticException("Unable to parse the given term."); } return(stack.Pop()); }
public void Cleanup() { _env = null; }
public void Initialize() { _env = new MathEnvironment(); }
/// <summary> /// Erstellt eine Baumstruktur, die einen mathematischen Term repräsentiert. /// </summary> /// <param name="readerInfixTerm">Der mathematische Term in der Infix-Notation.</param> /// <param name="environment">Die Umgebung, in dessen Kontext der mathematische Term seine Gültigkeit besitzt.</param> /// <param name="arrVariables">Eine Liste mit Variablen, die in dem Term vorkommen.</param> /// <returns>Eine Baumstruktur, die einen mathematischen Term repräsentiert.</returns> public static Node Get(TextReader readerInfixTerm, MathEnvironment environment, params string[] arrVariables) { return(Get(MathExpressionTokenizer.Tokenize(readerInfixTerm, true, arrVariables), environment, true)); }
/// <summary> /// Erstellt eine Baumstruktur, die einen mathematischen Term repräsentiert. /// </summary> /// <param name="strInfixTerm">Der mathematische Term in der Infix-Notation.</param> /// <param name="environment">Die Umgebung, in dessen Kontext der mathematische Term seine Gültigkeit besitzt.</param> /// <param name="arrVariables">Eine Liste mit Variablen, die in dem Term vorkommen.</param> /// <returns>Eine Baumstruktur, die einen mathematischen Term repräsentiert.</returns> public static Node Get(string strInfixTerm, MathEnvironment environment, params string[] arrVariables) { return(Get(new StringReader(strInfixTerm), environment, arrVariables)); }
public FactoryNode(TokenType type, string strValue, MathEnvironment environment, Node[] arrChildNodes) //, TransformationRule[] arrTransformationRules) : base(type, strValue, environment, arrChildNodes) //, arrTransformationRules) { }