Пример #1
0
        public static Express Parse(char[] sql, int beginIndex, int endIndex)
        {
            List <Word> wordList = Parser.GetWordList(sql, beginIndex, endIndex);

            List <Word> opList = new List <Word>();


            Operator op1 = null;
            Operator op2 = null;


            foreach (Word w in wordList)
            {
                if (w.type != WordType.NonWrapped)
                {
                    continue;
                }

                if (op1 == null)
                {
                    op1 = GetOperator(sql, w.iLeft, w.iRight);
                }
                else
                {
                    op2 = GetOperator(sql, w.iLeft, w.iRight);

                    if (op2 != null && op2.Priority <= op1.Priority)
                    {
                        op1 = op2;
                    }
                }
            }


            if (op1 == null)
            {
                //StrSpan s = StrUtil.Trim(sql, beginIndex, endIndex, Parser._whiteSpaces);

                //if ( s.isEmpty )
                //{
                //    throw new Exception()
                //}

                Content content = Parser.GetContent(sql, beginIndex, endIndex);

                if (content.isEmpty)
                {
                    return(null);
                    //throw new Exception("语法错误, 表达式 不能为空 。 在 第 " + content.iLeft + " 个字符 \"" + sql[content.iLeft] + "\" 。");
                }

                if (content.type == ContentType.String)
                {
                    return(new StringExpress(sql, content));
                }

                if (content.type == ContentType.Number)
                {
                    return(new NumberExpress(sql, content));
                }

                if (content.type == ContentType.Column)
                {
                    return(new ColumnExpress(sql, content));
                }

                return(Parse(sql, content.iLeft, content.iRight));
                //throw new Exception("缺少 运算符 。在 第 " + word.iLeft + " 个字符 \"" + sql[word.iLeft] + "\" 和 第 " + word.iLeft + " 个字符 \"" + sql[word.iRight] + "\" 之间 。");
            }


            Express express1 = null;
            Express express2 = null;

            if (op1.iLeft > beginIndex)
            {
                express1 = Parse(sql, beginIndex, op1.iLeft - 1);
            }

            if (op1.iRight < endIndex)
            {
                express2 = Parse(sql, op1.iRight + 1, endIndex);
            }

            Express express = new OperatorExpress(op1, express1, express2);

            return(express);
        }