示例#1
0
文件: Where.cs 项目: wj60387/hubble
        public override void DoThings(int action, Hubble.Framework.DataStructure.DFA <Hubble.Core.SFQL.LexicalAnalysis.Lexical.Token, WhereStateFunction> dfa)
        {
            Where where = dfa as Where;

            switch (Func)
            {
            case WhereStateFunction.LBracket:
                where.LastLogicFunc = LogicFunc.None;

                where.ExpressionTreeStack.Push(where.CurrentExpressionTree);
                where.CurrentExpressionTree = new ExpressionTree(null);
                break;

            case WhereStateFunction.RBracket:
                where.LastLogicFunc = LogicFunc.None;

                if (where.ExpressionTreeStack.Count <= 0)
                {
                    throw new SyntaxException("Half-baked bracket", where,
                                              new Hubble.Framework.DataStructure.DFAException("Half-baked bracket",
                                                                                              action, -1), dfa.CurrentToken);
                }

                ExpressionTree upTree = where.ExpressionTreeStack.Pop();

                while (where.CurrentExpressionTree.Parent != null)
                {
                    where.CurrentExpressionTree = where.CurrentExpressionTree.Parent;
                }

                upTree.Expression           = where.CurrentExpressionTree;
                where.CurrentExpressionTree = upTree;
                break;

            case WhereStateFunction.Left:
                if (where.CurrentExpressionTree.Expression == null)
                {
                    where.CurrentExpressionTree.Expression = new Expression();
                }

                ((Expression) where.CurrentExpressionTree.Expression).Left.Add(dfa.CurrentToken);
                break;

            case WhereStateFunction.Right:
                ((Expression) where.CurrentExpressionTree.Expression).Right.Add(dfa.CurrentToken);
                break;

            case WhereStateFunction.Operator:
                ((Expression) where.CurrentExpressionTree.Expression).Operator = dfa.CurrentToken;
                break;

            case WhereStateFunction.AndOr:
                switch (dfa.CurrentToken.SyntaxType)
                {
                case SyntaxType.AND:
                    if (where.LastLogicFunc == LogicFunc.Or)
                    {
                        throw new SyntaxException("And Or can't in same short sentence without bracket. Eg. a > 0 and c < 10 or b > 0 must be a > 0 and c < 10 or (b > 0) ",
                                                  where, new Hubble.Framework.DataStructure.DFAException("Half-baked bracket",
                                                                                                         action, -1), dfa.CurrentToken);
                    }

                    where.LastLogicFunc = LogicFunc.And;
                    where.CurrentExpressionTree.AndChild = new ExpressionTree(where.CurrentExpressionTree);
                    where.CurrentExpressionTree          = where.CurrentExpressionTree.AndChild;

                    break;

                case SyntaxType.OR:
                    if (where.LastLogicFunc == LogicFunc.And)
                    {
                        throw new SyntaxException("And Or can't in same short sentence without bracket. Eg. a > 0 and c < 10 or b > 0 must be a > 0 and c < 10 or (b > 0) ",
                                                  where, new Hubble.Framework.DataStructure.DFAException("Half-baked bracket",
                                                                                                         action, -1), dfa.CurrentToken);
                    }

                    where.LastLogicFunc = LogicFunc.Or;


                    where.CurrentExpressionTree.OrChild = new ExpressionTree(where.CurrentExpressionTree);
                    where.CurrentExpressionTree         = where.CurrentExpressionTree.OrChild;
                    break;
                }
                break;

            case WhereStateFunction.Quit:
                if (where.ExpressionTreeStack.Count > 0)
                {
                    throw new SyntaxException("Half-baked bracket", where,
                                              new Hubble.Framework.DataStructure.DFAException("Half-baked bracket",
                                                                                              action, -1), dfa.CurrentToken);
                }
                break;
            }
        }
示例#2
0
 public ExpressionTree(ExpressionTree parent)
 {
     Parent = parent;
 }