예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <summary>
        /// Stellt der Fabrik eine neue Vorlage zur Verfügung, aus der Baumstrukturen erstellt werden.
        /// </summary>
        /// <param name="template">Die Vorlage, die henzugefügt werden soll.</param>
        internal static void AddTemplate(NodeTemplate template)
        {
            if (!_dicTemplates.ContainsKey(template.Type))
            {
                _dicTemplates.Add(template.Type, new List <NodeTemplate>());
            }

            _dicTemplates[template.Type].Add(template);
        }