public SyntaxTree Build(TokenTree tokenTree)
        {
            TokenListParser parser = new TokenListParser(parseProperties);
            SyntaxNode      root   = parser.parse(tokenTree.RootTokens);

            return(new SyntaxTree(root));
        }
Beispiel #2
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());
        }
Beispiel #3
0
        protected RadicalNode processRadicalToken(RadicalToken radical)
        {
            TokenListParser radicalParser = new TokenListParser(properties);

            SyntaxNode baseNode   = radicalParser.parse(radical.Base);
            SyntaxNode degreeNode = radicalParser.parse(radical.Degree);

            return(new RadicalNode(baseNode, degreeNode));
        }
Beispiel #4
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));
        }
Beispiel #5
0
        protected DivisionNode processFraction(FractionToken fraction)
        {
            TokenListParser fractionParser = new TokenListParser(properties);

            SyntaxNode left  = fractionParser.parse(fraction.Numerator);
            SyntaxNode right = fractionParser.parse(fraction.Denominator);

            return(new DivisionNode(left, right));
        }
Beispiel #6
0
        protected ArgumentListNode parseArgumentList(DelimiterToken argumentList)
        {
            if (argumentList.BeginChar != '(' || argumentList.EndChar != ')' || argumentList.Delimiter != ',')
            {
                throw new ParseException(argumentList.simpleRepresentation() +
                                         " cannot be used as an argument list for a function call.");
            }

            ArgumentListNode argumentListNode = new ArgumentListNode();

            foreach (TokenList argument in argumentList.Elements)
            {
                TokenListParser argumentParser   = new TokenListParser(properties);
                SyntaxNode      argumentRootNode = argumentParser.parse(argument);
                argumentListNode.addArgument(argumentRootNode);
            }

            return(argumentListNode);
        }
Beispiel #7
0
        protected SyntaxNode processParenthesesToken(ParenthesesToken parentheses)
        {
            TokenListParser listParser = new TokenListParser(properties);

            return(listParser.parse(parentheses.Elements));
        }