예제 #1
0
        static void DefineFunctionInput(UndefinedFunctionTreeNode fDefinition, string expressionInput, CalculationContext context)
        {
            string[] parameterNames = new string[fDefinition.Parameters.Length];
            for (int i = 0; i < parameterNames.Length; ++i)
            {
                if (fDefinition.Parameters[i] is UndefinedVariableTreeNode vTreeNode)
                {
                    parameterNames[i] = vTreeNode.Name;
                }
                else
                {
                    throw new Exception("Invalid function definition");
                }
            }
            Token[]          tokens   = lexer.Tokenize(expressionInput);
            TreeNode         tree     = parser.Construct(tokens);
            FinishedFunction function = linker.BuildFunction(tree, context, parameterNames);

            context.FunctionTable.AssignItem(fDefinition.Name, function);
        }