コード例 #1
0
        protected SyntaxNode processFuncApplyToken(FunctionApplyToken func)
        {
            TokenList fNameNode = func.FunctionName;

            if (fNameNode.Count == 1)
            {
                if (fNameNode[0] is Lexeme)
                {
                    // Samo naziv funkcije u fName, bez ikakvih eksponenata i sl.
                    String functionName = (fNameNode[0] as Lexeme).Value;
                    if (properties.IsFunctionName(functionName))
                    {
                        int nArguments             = properties.getFunctionArgumentsCount(functionName);
                        ArgumentListNode arguments = parseArgumentList(func.Arguments, nArguments);

                        if (arguments.Count != nArguments)
                        {
                            throw new ParseException(
                                      "Number of arguments given doesn't match function declaration for function: " +
                                      func.simpleRepresentation());
                        }

                        FunctionApplyNode.FunctionBody definition = properties.getFunctionDefinition(functionName);
                        return(new FunctionApplyNode(arguments, definition, functionName));
                    }
                }
                else if (fNameNode[0] is SuperscriptToken)
                {
                    // eksponent u nazivu funkcije, npr. sin^-1(x)
                    SuperscriptToken sup = fNameNode[0] as SuperscriptToken;
                    if (sup.Base.Count == 1 && sup.Base[0] is TextRunToken)
                    {
                        String functionName = (sup.Base[0] as TextRunToken).Text;
                        if (properties.IsFunctionName(functionName))
                        {
                            int nArguments             = properties.getFunctionArgumentsCount(functionName);
                            ArgumentListNode arguments = parseArgumentList(func.Arguments, nArguments);

                            if (arguments.Count != nArguments)
                            {
                                throw new ParseException(
                                          "Number of arguments given doesn't match function declaration for function: " +
                                          func.simpleRepresentation());
                            }

                            TokenListParser exponentParser   = new TokenListParser(properties);
                            SyntaxNode      exponentArgument = exponentParser.parse(sup.Argument);

                            FunctionApplyNode.FunctionBody definition = properties.getFunctionDefinition(functionName);
                            FunctionApplyNode exponentBase            = new FunctionApplyNode(arguments, definition, functionName);

                            return(new PowerNode(exponentBase, exponentArgument));
                        }
                    }
                }
            }

            throw new ParseException("Can't process function name: " + func.simpleRepresentation());
        }
コード例 #2
0
        protected PowerNode processSuperscriptToken(SuperscriptToken superscript)
        {
            TokenListParser supParser = new TokenListParser(properties);

            SyntaxNode baseNode     = supParser.parse(superscript.Base);
            SyntaxNode argumentNode = supParser.parse(superscript.Argument);

            return(new PowerNode(baseNode, argumentNode));
        }