Пример #1
0
        public (String, int) IdentifyFirstTopLevelOperator(String Expression)
        {
            (String, int)Result = ("", -1);

            if (Expression == null)
            {
                return(Result);
            }
            String SanitizedExpression = ParseUtil.SqueezeWhiteSpace(Expression);

            if (Expression == null || Expression.Length == 0 || !ContainsOperator(Expression))
            {
                return(Result);
            }

            Boolean InString                    = false;
            int     CurrentDepthLevel           = 0;
            String  AccumulatedPossibleOperator = "";

            int    MaximumOperatorLevel = -1;
            int    MaximumOperatorIndex = -1;
            int    i = -1;
            String MaximumOperator = "";

            foreach (char c in SanitizedExpression)
            {
                i++;

                if (c == '"')
                {
                    InString = !InString;
                    continue;
                }

                if (InString)
                {
                    continue;
                }

                if (c == '(')
                {
                    CurrentDepthLevel++;
                    continue;
                }

                if (c == ')')
                {
                    CurrentDepthLevel--;
                    continue;
                }

                if (CurrentDepthLevel > 0)
                {
                    continue;
                }

                /*if (char.IsWhiteSpace(c))
                 * {
                 *  continue;
                 * }*/

                AccumulatedPossibleOperator += c;

                int CurrentOperatorLevel = OperatorLevel(AccumulatedPossibleOperator);

                if (CurrentOperatorLevel > MaximumOperatorLevel)
                {
                    MaximumOperatorIndex = i - AccumulatedPossibleOperator.Length + 1;
                    MaximumOperatorLevel = CurrentOperatorLevel;
                    MaximumOperator      = AccumulatedPossibleOperator;
                }

                if (AccumulatedPossibleOperator.Length >= LongestOperatorLength || CurrentOperatorLevel == -1)
                {
                    AccumulatedPossibleOperator = "";
                }

                if (MaximumOperatorLevel == LeveledOperators.Count - 1)
                {
                    break;
                }
            }

            if (MaximumOperatorLevel != -1)
            {
                Result = (MaximumOperator, MaximumOperatorIndex);
            }

            return(Result);
        }
Пример #2
0
        public EXEASTNode ConstructAST(String ExpressionCommand)
        {
            throw new NotImplementedException();

            //Console.WriteLine("ConstrAST:" + ExpressionCommand + "EOL");

            EXEASTNode AST = null;
            // EXEQueryChecker QueryChecker = new EXEQueryChecker();

            String ClearedExpressionCommand = ParseUtil.SqueezeWhiteSpace(ExpressionCommand);

            // Bollock - think about (5 + 6) * (5 + 7)

            /*while ("(".Equals(ClearedExpressionCommand[0]) && ")".Equals(ClearedExpressionCommand[ExpressionCommand.Length - 1]))
             * {
             *  ClearedExpressionCommand = ClearedExpressionCommand.Substring(1, ClearedExpressionCommand.Length - 2);
             * }*/

            /* if ("\"".Equals(ClearedExpressionCommand[0]) && "\"".Equals(ClearedExpressionCommand[ExpressionCommand.Length - 1]))
             * {
             *  // AST = new EXEASTNodeLeaf(ExpressionCommand, false, false, false);
             * }
             * //First go for query
             * else if (QueryChecker.IsQuery(ClearedExpressionCommand))
             * {
             *  // Console.WriteLine("OALCP B4Constructing Query AST:" + ExpressionCommand);
             *   AST = QueryChecker.ConstructQueryAST(ClearedExpressionCommand);
             *  // Console.WriteLine("OALCP AfterConstructing Query AST:" + ExpressionCommand);
             * }
             * //Then go for top level commands -> control (return, break, continue)
             * else if (IsControlCommand(ClearedExpressionCommand))
             * {
             *   AST = ConstructControlCommandAST(ClearedExpressionCommand);
             * }
             * //Then go for top level commands -> assign
             * else if (IsAssignment(ClearedExpressionCommand))
             * {
             *  // Console.WriteLine("OALCP B4Constructing Assignment AST:" + ExpressionCommand);
             *   AST = ConstructAssignmentCommandAST(ClearedExpressionCommand);
             *  // Console.WriteLine("OALCP AfterConstructing Assignment AST:" + ExpressionCommand);
             * }
             * //Then if it has operator, it is an expression and needs to be treated as such
             * else if (ContainsOperator(ClearedExpressionCommand))
             * {
             *   AST = ConstructExprASTAlt(ClearedExpressionCommand);
             * }
             * //If we got here, we have leaf node -> variable/attribute/method name or literal value
             * else
             * {
             *   while (ClearedExpressionCommand[0] == '(' && ClearedExpressionCommand[ClearedExpressionCommand.Length - 1] == ')')
             *   {
             *       ClearedExpressionCommand = ClearedExpressionCommand.Substring(1, ClearedExpressionCommand.Length - 2);
             *       ClearedExpressionCommand = EXEParseUtil.SqueezeWhiteSpace(ClearedExpressionCommand);
             *   }
             *
             *   AST = new EXEASTNodeLeaf(EXEParseUtil.SqueezeWhiteSpace(ClearedExpressionCommand));
             * }*/

            //Console.WriteLine("OALCP:" + ExpressionCommand);
            return(AST);
        }