Example #1
0
        private void ProcessVariable(TreeFunctional tree, ref int i, ref Token currentToken, bool withAssign = true)
        {
            Token nextToken = GetNextToken(ref i, tree);

            if (nextToken.type == TokenType.ASSIGN || !withAssign)
            {
                if (withAssign)
                {
                    nextToken = GetNextToken(ref i, tree);
                }

                var type = nextToken.type;
                if (type == TokenType.FUNCTION)
                {
                    nextToken = ProcessFunction(tree, ref i, ref nextToken);
                    if (nextToken == null)
                    {
                        throw new Exception("Expected return value in function, Line:" + i);
                    }
                    (currentToken as TokenVariable).data    = (nextToken as TokenVariable).data;
                    (currentToken as TokenVariable).varType = (nextToken as TokenVariable).varType;
                    nextToken = GetNextToken(ref i, tree);
                    type      = nextToken.type;
                }


                if (type == TokenType.NUMERIC_CONST || type == TokenType.ARITHMETIC_BRACKET_OPEN ||
                    (type == TokenType.VARIABLE && (nextToken as TokenVariable).varType != VariableType.STRING))
                {
                    ArichmetichTree arTree = new ArichmetichTree(currentToken as TokenVariable);
                    tree.next = arTree;
                    int numBracket = nextToken.type == TokenType.ARITHMETIC_BRACKET_OPEN ? 1 : 0;

                    while (nextToken.type != TokenType.END_OP && nextToken.type != TokenType.COMA && (nextToken.type != TokenType.ARITHMETIC_BRACKET_CLOSE || numBracket == 0))
                    {
                        arTree.PutToken(nextToken);
                        nextToken = GetNextToken(ref i, tree);

                        switch (nextToken.type)
                        {
                        case TokenType.ARITHMETIC_BRACKET_OPEN:
                            numBracket++;
                            break;

                        case TokenType.ARITHMETIC_BRACKET_CLOSE:
                            numBracket--;
                            break;

                        case TokenType.FUNCTION:
                            nextToken = ProcessFunction(tree, ref i, ref nextToken);
                            if (nextToken == null)
                            {
                                throw new Exception("Expected return value in function, Line:" + i);
                            }
                            break;
                        }
                    }
                }
                else
                if (type == TokenType.VARIABLE && (type == TokenType.VARIABLE && (nextToken as TokenVariable).varType != VariableType.NUMERIC))
                {
                    StringTree strTree = new StringTree(currentToken as TokenVariable);
                    tree.next = strTree;

                    while (nextToken.type != TokenType.END_OP && nextToken.type != TokenType.COMA && nextToken.type != TokenType.ARITHMETIC_BRACKET_CLOSE)
                    {
                        strTree.AddToken(nextToken as TokenVariable);
                        nextToken = GetNextToken(ref i, tree);
                        if (nextToken.type == TokenType.END_OP || nextToken.type == TokenType.ARITHMETIC_BRACKET_CLOSE)
                        {
                            break;
                        }

                        if (nextToken.type != TokenType.PLUS)
                        {
                            throw new Exception("Expect \'+\' in line:" + i.ToString());
                        }

                        nextToken = GetNextToken(ref i, tree);
                        if (nextToken.type == TokenType.FUNCTION)
                        {
                            nextToken = ProcessFunction(tree, ref i, ref nextToken);
                            if (nextToken == null)
                            {
                                throw new Exception("Expected return value in function, Line:" + i);
                            }
                        }
                    }
                }
                else
                if (type == TokenType.END_OP)
                {
                    return;
                }
                else
                {
                    throw new Exception("Somethin bad in Process");
                }
            }
        }