コード例 #1
0
        public static (int Precedence, bool Left) GetOperatorData(EOperatorType op)
        {
            switch (op)
            {
            case EOperatorType.Unary_Negation:
                return(3, false);

            case EOperatorType.Bin_Greater:
                return(9, true);

            case EOperatorType.Bin_GreaterOrEqual:
                return(9, true);

            case EOperatorType.Bin_Equal:
                return(10, true);

            case EOperatorType.Bin_LesserOrEqual:
                return(9, true);

            case EOperatorType.Bin_NotEqual:
                return(9, true);

            case EOperatorType.Bin_Lesser:
                return(9, true);

            case EOperatorType.Bin_OR:
                return(15, true);

            case EOperatorType.Bin_AND:
                return(14, true);
            }
            return(1000, true);
        }
コード例 #2
0
ファイル: Define.cs プロジェクト: By2048/Windows
 public Operator(int dimension, int pri, EOperatorType type, string value)
 {
     Dimension = dimension;
     PRI       = pri;
     Type      = type;
     Value     = value;
 }
コード例 #3
0
        protected IConvertible CompareExact(double compare_val1, double compare_val2,
                                            EOperatorType compare_operator, double result_true, double result_false)
        {
            var _TRUE = false;

            switch (compare_operator)
            {
            case EOperatorType.Equal:
                if (compare_val1 == compare_val2)
                {
                    _TRUE = true;
                }
                break;

            case EOperatorType.Less:
                if (compare_val1 < compare_val2)
                {
                    _TRUE = true;
                }
                break;

            case EOperatorType.LessOrEqual:
                if (compare_val1 <= compare_val2)
                {
                    _TRUE = true;
                }
                break;

            case EOperatorType.More:
                if (compare_val1 > compare_val2)
                {
                    _TRUE = true;
                }
                break;

            case EOperatorType.MoreOrEqual:
                if (compare_val1 >= compare_val2)
                {
                    _TRUE = true;
                }
                break;

            case EOperatorType.NotEqual:
                if (compare_val1 != compare_val2)
                {
                    _TRUE = true;
                }
                break;

            default:
                throw new Exception("Сравнения не поддерживает оператор " + (int)compare_operator +
                                    ". (1 это >, 2 это <, 3 это >=, 4 это <=, 5 это ==, 6 это !=)");
            }
            if (_TRUE)
            {
                return(result_true);
            }
            return(result_false);
        }
コード例 #4
0
 public Expression(EOperatorType op) : this()
 {
     VType = op == EOperatorType.Unary_Negation ?
             EValueTypes.OP_UNARY :
             EValueTypes.OP_BINARY;
     _operator = op;
     // to mark it as 'not an error'
     _Val = new UnionValue(true);
 }
コード例 #5
0
        public Operator(EOperatorType operatorType)
        {
            switch (operatorType)
            {
            case EOperatorType.And:
                this.OperatorString = OperatorKeys.AND;
                break;

            case EOperatorType.Between:
                this.OperatorString = OperatorKeys.between;
                break;

            case EOperatorType.DoesNotEqual:
                this.OperatorString = OperatorKeys.doesNotEqual;
                break;

            case EOperatorType.Equals:
                this.OperatorString = OperatorKeys.equals;
                break;

            case EOperatorType.GreaterThan:
                this.OperatorString = OperatorKeys.greaterThan;
                break;

            case EOperatorType.GreaterThanOrEqual:
                this.OperatorString = OperatorKeys.greaterThanOrEqual;
                break;

            case EOperatorType.In:
                this.OperatorString = OperatorKeys.In;
                break;

            case EOperatorType.LessThan:
                this.OperatorString = OperatorKeys.lessThan;
                break;

            case EOperatorType.LessThanOrEqual:
                this.OperatorString = OperatorKeys.lessThanOrEqual;
                break;

            case EOperatorType.Like:
                this.OperatorString = OperatorKeys.Like;
                break;

            case EOperatorType.Or:
                this.OperatorString = OperatorKeys.OR;
                break;

            case EOperatorType.Not:
                this.OperatorString = OperatorKeys.NOT;
                break;
            }
        }
コード例 #6
0
        private static UnionValue EvaluateImpl(
            UnionValue LHS,
            UnionValue RHS,
            EOperatorType op)
        {
            if (RHS.IsError || LHS.IsError || op == EOperatorType.INVALID)
            {
                return(UnionValue.Error);
            }

            if (RHS.Type != LHS.Type)
            {
                UnityEngine.Debug.LogError("! type mismach");
            }

            switch (RHS.Type)
            {
            case EValType.FLOAT:
                return(new UnionValue(ExecAlg(op, RHS.AsFloat, LHS.AsFloat)));

            case EValType.BOOL:
                switch (op)
                {
                case EOperatorType.Bin_OR:
                    return(new UnionValue(LHS.AsBool || RHS.AsBool));

                case EOperatorType.Bin_AND:
                    return(new UnionValue(LHS.AsBool && RHS.AsBool));

                case EOperatorType.Bin_Equal:
                    return(new UnionValue(LHS.AsBool == RHS.AsBool));

                case EOperatorType.Bin_NotEqual:
                    return(new UnionValue(LHS.AsBool != RHS.AsBool));

                default:
                    return(UnionValue.Error);
                }

            case EValType.STR:
                return(UnionValue.Error);
            }

            return(UnionValue.Error);
        }
コード例 #7
0
        public static void Eval(ValueStack stack, EOperatorType op)
        {
            if (op == EOperatorType.Unary_Negation)
            {
                Negate(stack, op);
                return;
            }

            if (stack.Size < 2 || op == EOperatorType.INVALID)
            {
                stack.Push(UnionValue.Error);
                return;
            }

            var rhs = stack.Pop();
            var lhs = stack.Pop();

            stack.Push(EvaluateImpl(lhs, rhs, op));
        }
コード例 #8
0
        public static void Negate(ValueStack stack, EOperatorType op)
        {
            if (stack.Size < 1)
            {
                stack.Push(UnionValue.Error);
                return;
            }

            var rhs = stack.Pop();

            if (!rhs.IsError && (rhs.Type == EValType.BOOL))
            {
                stack.Push(new UnionValue(!rhs.AsBool));
            }
            else
            {
                stack.Push(UnionValue.Error);
                return;
            }
        }
コード例 #9
0
        public static T Compute <T>(T left, T right, EOperatorType computeType)
        {
            Type type = typeof(T);

            if (!Utils.IsAgentType(type) && !Utils.IsCustomClassType(type) && !Utils.IsCustomStructType(type) && !Utils.IsArrayType(type) && !Utils.IsStringType(type))
            {
                if (Utils.IsEnumType(type) || type == typeof(char))
                {
                    int iLeft  = Convert.ToInt32(left);
                    int iRight = Convert.ToInt32(right);

                    switch (computeType)
                    {
                    case EOperatorType.E_ADD: return((T)(object)Operator <int> .Add(iLeft, iRight));

                    case EOperatorType.E_SUB: return((T)(object)Operator <int> .Subtract(iLeft, iRight));

                    case EOperatorType.E_MUL: return((T)(object)Operator <int> .Multiply(iLeft, iRight));

                    case EOperatorType.E_DIV: return((T)(object)Operator <int> .Divide(iLeft, iRight));
                    }
                }
                else
                {
                    switch (computeType)
                    {
                    case EOperatorType.E_ADD: return(Operator <T> .Add(left, right));

                    case EOperatorType.E_SUB: return(Operator <T> .Subtract(left, right));

                    case EOperatorType.E_MUL: return(Operator <T> .Multiply(left, right));

                    case EOperatorType.E_DIV: return(Operator <T> .Divide(left, right));
                    }
                }
            }

            Debug.Check(false);
            return(left);
        }
コード例 #10
0
        public static bool ExecAlg <T>(EOperatorType token, T x, T y) where T : IComparable
        {
            switch (token)
            {
            case EOperatorType.Bin_Greater:
                return(x.CompareTo(y) > 0);

            case EOperatorType.Bin_GreaterOrEqual:
                return(x.CompareTo(y) >= 0);

            case EOperatorType.Bin_Equal:
                return(x.CompareTo(y) == 0);

            case EOperatorType.Bin_LesserOrEqual:
                return(x.CompareTo(y) <= 0);

            case EOperatorType.Bin_NotEqual:
                return(x.CompareTo(y) != 0);

            case EOperatorType.Bin_Lesser:
                return(x.CompareTo(y) < 0);
            }
            return(false);
        }
コード例 #11
0
ファイル: SyntaxAnalyzer.cs プロジェクト: tomyqg/SemiGC
        /// <summary>
        /// 去关键字后 检查标记应用环境(不检查操作符与数据类型匹配关系)
        /// </summary>
        /// <param name="startLink"></param>
        /// <param name="endLink"></param>
        private void TokenEnvirAnalyze(TOKENLink startLink, TOKENLink endLink)
        {
            TOKENLink curLink = startLink;

            while (true)
            {
                switch (curLink.Token.Type)
                {
                case ETokenType.token_keyword:
                    throw new Exception(string.Format("Error! 关键字“{0}”未解析(索引:{1})",
                                                      ((TOKEN <KeyWord>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));

                case ETokenType.token_operand:
                    if (curLink.Prev != null && (curLink.Prev.Token.Type == ETokenType.token_operand ||
                                                 (curLink.Prev.Token.Type == ETokenType.token_operator &&
                                                  ((TOKEN <Operator>)curLink.Prev.Token).Tag.Type == EOperatorType.RightParen)))
                    {
                        string err = "";
                        if (_operandSource[curLink.Token] == null)
                        {
                            err = string.Format("Error! 操作数“{0}”附近有语法错误(索引:{1})",
                                                ((TOKEN <IOperand>)curLink.Token).Tag.ToString(), curLink.Token.Index.ToString());
                        }
                        else
                        {
                            err = string.Format("Error! 关键字“{0}”附近有语法错误(索引:{1})",
                                                _operandSource[curLink.Token], curLink.Token.Index.ToString());
                        }

                        throw new Exception(err);
                    }

                    break;

                case ETokenType.token_operator:
                    EOperatorType type = ((TOKEN <Operator>)curLink.Token).Tag.Type;
                    switch (type)
                    {
                    case EOperatorType.Positive:          //正
                    case EOperatorType.Negative:          //负
                        if (!(curLink.Next != null && (curLink.Next.Token.Type == ETokenType.token_operand ||
                                                       (curLink.Next.Token.Type == ETokenType.token_operator &&
                                                        ((TOKEN <Operator>)curLink.Next.Token).Tag.Type == EOperatorType.LeftParen))))
                        {
                            throw new Exception(string.Format("Error! 一元操作符“{0}”附近有语法错误(索引:{1})",
                                                              ((TOKEN <Operator>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));
                        }

                        break;

                    case EOperatorType.LeftParen:
                        if (curLink.Prev != null && (curLink.Prev.Token.Type == ETokenType.token_operand ||
                                                     (curLink.Prev.Token.Type == ETokenType.token_operator &&
                                                      ((TOKEN <Operator>)curLink.Prev.Token).Tag.Type == EOperatorType.RightParen)))
                        {
                            throw new Exception(string.Format("Error! 左括弧“{0}”附近有语法错误(索引:{1})",
                                                              ((TOKEN <Operator>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));
                        }

                        break;

                    case EOperatorType.RightParen:
                        if (curLink.Prev == null || (curLink.Prev.Token.Type == ETokenType.token_operator &&
                                                     ((TOKEN <Operator>)curLink.Prev.Token).Tag.Type == EOperatorType.LeftParen))
                        {
                            throw new Exception(string.Format("Error! 右括弧“{0}”附近有语法错误(索引:{1})",
                                                              ((TOKEN <Operator>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));
                        }

                        break;

                    default:
                        if (!((curLink.Prev != null && (curLink.Prev.Token.Type == ETokenType.token_operand ||
                                                        (curLink.Prev.Token.Type == ETokenType.token_operator &&
                                                         ((TOKEN <Operator>)curLink.Prev.Token).Tag.Type == EOperatorType.RightParen))) &&
                              (curLink.Next != null && (curLink.Next.Token.Type == ETokenType.token_operand ||
                                                        (curLink.Next.Token.Type == ETokenType.token_operator &&
                                                         (((TOKEN <Operator>)curLink.Next.Token).Tag.Type == EOperatorType.LeftParen ||
                                                          ((TOKEN <Operator>)curLink.Next.Token).Tag.Type == EOperatorType.Negative ||
                                                          ((TOKEN <Operator>)curLink.Next.Token).Tag.Type == EOperatorType.Positive))))))
                        {
                            throw new Exception(string.Format("Error! 二元操作符“{0}”附近有语法错误(索引:{1})",
                                                              ((TOKEN <Operator>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));
                        }

                        break;
                    }

                    break;

                case ETokenType.token_separator:
                    throw new Exception(string.Format("Error! 分隔符“{0}”只能用于关键字(索引:{1})",
                                                      ((TOKEN <Separator>)curLink.Token).Tag.Value, curLink.Token.Index.ToString()));

                default:
                    break;
                }

                if (curLink == endLink)
                {
                    break;
                }
                else
                {
                    curLink = curLink.Next;
                }
            }
        }
コード例 #12
0
ファイル: AttachAction.cs プロジェクト: 675492062/behaviac
        public virtual bool load(List<property_t> properties)
        {
            string opr2TypeName = null;
            string comparatorName = null;

            foreach(property_t p in properties)
            {
                if (p.name == "Mode")
                {
                    switch (p.value)
                    {
                        case "Condition":
                            this.m_mode = TransitionMode.Condition;
                            break;

                        case "Success":
                            this.m_mode = TransitionMode.Success;
                            break;

                        case "Failure":
                            this.m_mode = TransitionMode.Failure;
                            break;

                        case "End":
                            this.m_mode = TransitionMode.End;
                            break;
                    }
                }
                else if (p.name == "Opl")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            string typeName = null;
                            this.m_opl = Condition.LoadRight(p.value, ref typeName);
                        }
                        else
                        {
                            //method
                            this.m_opl_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else if (p.name == "Opr1")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            string typeName = null;
                            this.m_opr1 = Condition.LoadRight(p.value, ref typeName);
                        }
                        else
                        {
                            //method
                            this.m_opr1_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else if (p.name == "Operator")
                {
                    comparatorName = p.value;

                    switch (p.value)
                    {
                        case "Invalid":
                            this.m_operator = EOperatorType.E_INVALID;
                            break;

                        case "Assign":
                            this.m_operator = EOperatorType.E_ASSIGN;
                            break;

                        case "Add":
                            this.m_operator = EOperatorType.E_ADD;
                            break;

                        case "Sub":
                            this.m_operator = EOperatorType.E_SUB;
                            break;

                        case "Mul":
                            this.m_operator = EOperatorType.E_MUL;
                            break;

                        case "Div":
                            this.m_operator = EOperatorType.E_DIV;
                            break;

                        case "Equal":
                            this.m_operator = EOperatorType.E_EQUAL;
                            break;

                        case "NotEqual":
                            this.m_operator = EOperatorType.E_NOTEQUAL;
                            break;

                        case "Greater":
                            this.m_operator = EOperatorType.E_GREATER;
                            break;

                        case "Less":
                            this.m_operator = EOperatorType.E_LESS;
                            break;

                        case "GreaterEqual":
                            this.m_operator = EOperatorType.E_GREATEREQUAL;
                            break;

                        case "LessEqual":
                            this.m_operator = EOperatorType.E_LESSEQUAL;
                            break;
                    }
                }
                else if (p.name == "Opr2")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            this.m_opr2 = Condition.LoadRight(p.value, ref opr2TypeName);
                        }
                        else
                        {
                            //method
                            this.m_opr2_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }

            // compare
            if (this.m_operator >= EOperatorType.E_EQUAL && this.m_operator <= EOperatorType.E_LESSEQUAL)
            {
                if (!string.IsNullOrEmpty(comparatorName) && (this.m_opl != null || this.m_opl_m != null) &&
                    (this.m_opr2 != null || this.m_opr2_m != null))
                {
                    this.m_comparator = Condition.Create(comparatorName, this.m_opl, this.m_opl_m, this.m_opr2, this.m_opr2_m);
                }
            }

            return this.m_opl != null;
        }
コード例 #13
0
        /// <summary>
        /// 加入链表
        /// </summary>
        /// <param name="startpos">开始位</param>
        /// <param name="endpos">结束位</param>
        /// <param name="state">处理状态</param>
        private void AddToLink(int startpos, int endpos, EDFAState state)
        {
            string temp  = null;
            IToken token = null;

            if (endpos >= 0 && startpos >= 0 && endpos >= startpos)
            {
                temp = _expression.Substring(startpos, endpos - startpos + 1);

                if (state == EDFAState.CharStr)
                {
                    //字符串格式为"abcd" 转换为 adbc
                    if (temp.Length == 2)
                    {
                        temp = string.Empty;
                    }
                    else
                    {
                        temp = temp.Substring(1, temp.Length - 1).Substring(0, temp.Length - 2).Replace("\\\"", "\"");
                    }
                }
                else
                {
                    //处理标记中的空格换行符等 例如:8 8,an  d 转换为88,and
                    temp = temp.Replace(" ", "").Replace("\r\n", "").Replace("\t", "");
                }

                switch (state)
                {
                case EDFAState.IntStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint, Convert.ToInt32(temp)), startpos);

                    break;

                case EDFAState.DoubleStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble, Convert.ToDouble(temp)), startpos);

                    break;

                case EDFAState.CharStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <string>(EDataType.Dstring, temp), startpos);
                    break;

                case EDFAState.Comma:
                    token = new TOKEN <Separator>(ETokenType.token_separator, new Separator(','), startpos);
                    break;

                case EDFAState.ABCStr:
                    foreach (string name in Enum.GetNames(typeof(EKeyword)))
                    {
                        if (name.ToLower().Equals(temp.ToLower()))
                        {
                            token = new TOKEN <KeyWord>(ETokenType.token_keyword, Define.KeyWords[(EKeyword)Enum.Parse(typeof(EKeyword), temp, true)], startpos);
                            break;
                        }
                    }

                    if (token == null)
                    {
                        //非法字
                        throw new Exception(string.Format("Error! 非法关键字“{0}”(索引:{1})", temp, startpos.ToString()));
                    }

                    break;

                case EDFAState.OperatorStr:
                    bool          flag = true;
                    EOperatorType type = EOperatorType.Plus;
                    switch (temp)
                    {
                    case "(":
                        type = EOperatorType.LeftParen;
                        break;

                    case ")":
                        type = EOperatorType.RightParen;
                        break;

                    case "+":
                    case "-":
                        if (_link_OP.Tail != null && ((_link_OP.Tail.Token.Type == ETokenType.token_operand) ||
                                                      (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                       ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.RightParen)))
                        {
                            if (temp == "-")
                            {
                                type = EOperatorType.Minus;
                            }
                            else
                            {
                                type = EOperatorType.Plus;
                            }
                        }
                        else
                        {
                            if (temp == "-")
                            {
                                type = EOperatorType.Negative;
                            }
                            else
                            {
                                type = EOperatorType.Positive;
                            }
                        }
                        break;

                    case "*":
                        type = EOperatorType.Multiply;
                        break;

                    case "/":
                        type = EOperatorType.Divide;
                        break;

                    case "%":
                        type = EOperatorType.Mod;
                        break;

                    case "<":
                        type = EOperatorType.LessThan;
                        break;

                    case ">":
                        if (_link_OP.Tail != null && (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                      ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.LessThan))
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.NotEqual];
                            flag = false;
                        }
                        else
                        {
                            type = EOperatorType.GreaterThan;
                        }
                        break;

                    case "=":
                        if (_link_OP.Tail != null && (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                      ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.LessThan))
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.LessEqual];
                            flag = false;
                        }
                        else if (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                 ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.GreaterThan)
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.GreaterEqual];
                            flag = false;
                        }
                        else
                        {
                            type = EOperatorType.Equal;
                        }
                        break;

                    default:
                        break;
                    }

                    if (flag)
                    {
                        token = new TOKEN <Operator>(ETokenType.token_operator, Define.Operators[type], startpos);
                    }

                    break;

                default:
                    break;
                }

                if (token != null)
                {
                    _link_OP.Add(new TOKENLink(token));
                }
            }
        }
コード例 #14
0
ファイル: Evaluator.cs プロジェクト: By2048/Windows
        /// <summary>
        /// 表达式求值
        /// </summary>
        /// <param name="startLink"></param>
        /// <param name="endLink"></param>
        /// <returns></returns>
        public IOperand ExpressionEvaluate(TOKENLink startLink, TOKENLink endLink)
        {
            TOKENLink postfixLink = _toolBox.InfixToPostfix(startLink, endLink);
            TOKENLink link_new    = null;
            IToken    token       = null;

            while (postfixLink.Next != null)
            {
                postfixLink = postfixLink.Next;

                if (postfixLink.Token.Type == ETokenType.token_operator)
                {
                    link_new = null;
                    token    = null;
                    EOperatorType type = ((TOKEN <Operator>)postfixLink.Token).Tag.Type;
                    switch (type)
                    {
                    case EOperatorType.Positive:      //正
                    case EOperatorType.Negative:      //负
                        IOperand operand = ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag;
                        if (type == EOperatorType.Negative)
                        {
                            if (operand.Type == EDataType.Dint)
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand,
                                                             new Operand <int>(EDataType.Dint, -((Operand <int>)operand).TValue), postfixLink.Token.Index);
                            }
                            else if (operand.Type == EDataType.Ddouble)
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand,
                                                             new Operand <double>(EDataType.Ddouble, -((Operand <double>)operand).TValue), postfixLink.Token.Index);
                            }
                        }
                        else
                        {
                            token = postfixLink.Prev.Token;
                        }

                        break;

                    case EOperatorType.Plus:
                    case EOperatorType.Minus:
                        if (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dstring ||
                            ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dstring)
                        {
                            if (type == EOperatorType.Plus)
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand,
                                                             new Operand <string>(EDataType.Dstring, ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.ToString() +
                                                                                  ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.ToString()), postfixLink.Token.Index);
                            }
                            else
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand,
                                                             new Operand <string>(EDataType.Dstring,
                                                                                  ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.ToString().Replace(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.ToString(), "")),
                                                             postfixLink.Token.Index);
                            }
                        }
                        else if (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddouble ||
                                 ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddouble)
                        {
                            if (type == EOperatorType.Plus)
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble,
                                                                                                            Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value) +
                                                                                                            Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value)), postfixLink.Token.Index);
                            }
                            else
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble,
                                                                                                            Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value) -
                                                                                                            Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value)), postfixLink.Token.Index);
                            }
                        }
                        else
                        {
                            if (type == EOperatorType.Plus)
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint,
                                                                                                         ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag).TValue +
                                                                                                         ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Token).Tag).TValue), postfixLink.Token.Index);
                            }
                            else
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint,
                                                                                                         ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag).TValue -
                                                                                                         ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Token).Tag).TValue), postfixLink.Token.Index);
                            }
                        }

                        break;

                    case EOperatorType.Multiply:
                        if (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddouble ||
                            ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddouble)
                        {
                            token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble,
                                                                                                        Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value) *
                                                                                                        Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value)), postfixLink.Token.Index);
                        }
                        else
                        {
                            token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint,
                                                                                                     ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag).TValue *
                                                                                                     ((Operand <int>)((TOKEN <IOperand>)postfixLink.Prev.Token).Tag).TValue), postfixLink.Token.Index);
                        }

                        break;

                    case EOperatorType.Divide:
                        token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble,
                                                                                                    Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value) /
                                                                                                    Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value)), postfixLink.Token.Index);

                        break;

                    case EOperatorType.Mod:
                        token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble,
                                                                                                    Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value) %
                                                                                                    Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value)), postfixLink.Token.Index);

                        break;

                    case EOperatorType.LessThan:
                    case EOperatorType.GreaterThan:
                    case EOperatorType.GreaterEqual:
                    case EOperatorType.LessEqual:
                        bool result = false;

                        double first  = Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value);
                        double second = Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value);

                        switch (type)
                        {
                        case EOperatorType.LessThan:
                            result = first < second;
                            break;

                        case EOperatorType.GreaterThan:
                            result = first > second;
                            break;;

                        case EOperatorType.GreaterEqual:
                            result = first >= second;
                            break;

                        case EOperatorType.LessEqual:
                            result = first <= second;
                            break;
                        }

                        token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <bool>(EDataType.Dbool, result), postfixLink.Token.Index);

                        break;

                    case EOperatorType.Equal:
                    case EOperatorType.NotEqual:
                        bool r = false;
                        if (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dstring &&
                            ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dstring)
                        {
                            if (type == EOperatorType.Equal)
                            {
                                r = ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.ToString().Equals(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.ToString());
                            }
                            else
                            {
                                r = !((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.ToString().Equals(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.ToString());
                            }
                        }
                        else if (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dbool &&
                                 ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dbool)
                        {
                            bool f = ((Operand <bool>)((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag).TValue;
                            bool s = ((Operand <bool>)((TOKEN <IOperand>)postfixLink.Prev.Token).Tag).TValue;

                            if (type == EOperatorType.Equal)
                            {
                                r = f == s;
                            }
                            else
                            {
                                r = f != s;
                            }
                        }
                        else
                        {
                            double f = Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Value);
                            double s = Convert.ToDouble(((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Value);

                            if (type == EOperatorType.Equal)
                            {
                                r = f == s;
                            }
                            else
                            {
                                r = f != s;
                            }
                        }

                        token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <bool>(EDataType.Dbool, r), postfixLink.Token.Index);

                        break;

                    default:
                        break;
                    }

                    if (token != null)
                    {
                        link_new = new TOKENLink(token);

                        link_new.Next = postfixLink.Next;
                        if (postfixLink.Next != null)
                        {
                            postfixLink.Next.Prev = link_new;
                        }

                        if (((TOKEN <Operator>)postfixLink.Token).Tag.Dimension == 1)
                        {
                            //一元操作符
                            if (postfixLink.Prev.Prev != null)
                            {
                                link_new.Prev = postfixLink.Prev.Prev;
                                postfixLink.Prev.Prev.Next = link_new;
                            }
                        }
                        else if (((TOKEN <Operator>)postfixLink.Token).Tag.Dimension == 2)
                        {
                            //二元操作符
                            if (postfixLink.Prev.Prev.Prev != null)
                            {
                                link_new.Prev = postfixLink.Prev.Prev.Prev;
                                postfixLink.Prev.Prev.Prev.Next = link_new;
                            }
                        }

                        postfixLink = link_new;
                    }
                } //end if
            }     //end while

            return(((TOKEN <IOperand>)postfixLink.Token).Tag);
        }
コード例 #15
0
ファイル: AttachAction.cs プロジェクト: yangjunhua/behaviac
            public virtual bool load(List<property_t> properties)
            {
                for (int i = 0; i < properties.Count; ++i)
                {
                    property_t p = properties[i];
                    if (p.name == "Mode")
                    {
                        switch (p.value)
                        {
                            case "Condition":
                                this.m_mode = TransitionMode.Condition;
                                break;

                            case "Success":
                                this.m_mode = TransitionMode.Success;
                                break;

                            case "Failure":
                                this.m_mode = TransitionMode.Failure;
                                break;

                            case "End":
                                this.m_mode = TransitionMode.End;
                                break;
                        }
                    }
                    else if (p.name == "Opl")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opl = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opl = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Opr1")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr1 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr1 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Operator")
                    {
                        this.m_operator = OperationUtils.ParseOperatorType(p.value);
                    }
                    else if (p.name == "Opr2")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr2 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr2 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                }

                return this.m_opl != null;
            }
コード例 #16
0
            public virtual bool load(List <property_t> properties)
            {
                for (int i = 0; i < properties.Count; ++i)
                {
                    property_t p = properties[i];
                    if (p.name == "Mode")
                    {
                        switch (p.value)
                        {
                        case "Condition":
                            this.m_mode = TransitionMode.Condition;
                            break;

                        case "Success":
                            this.m_mode = TransitionMode.Success;
                            break;

                        case "Failure":
                            this.m_mode = TransitionMode.Failure;
                            break;

                        case "End":
                            this.m_mode = TransitionMode.End;
                            break;
                        }
                    }
                    else if (p.name == "Opl")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opl = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opl = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Opr1")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr1 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr1 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Operator")
                    {
                        this.m_operator = OperationUtils.ParseOperatorType(p.value);
                    }
                    else if (p.name == "Opr2")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr2 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr2 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                }

                return(this.m_opl != null);
            }
コード例 #17
0
ファイル: AttachAction.cs プロジェクト: Just4F/behaviac
            public virtual bool load(List<property_t> properties)
            {
                for (int i = 0; i < properties.Count; ++i)
                {
                    property_t p = properties[i];
      
                    if (p.name == "Opl")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opl = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opl = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Opr1")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr1 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr1 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Operator")
                    {
                        this.m_operator = OperationUtils.ParseOperatorType(p.value);
                    }
                    else if (p.name == "Opr2")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr2 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr2 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                }

                return this.m_opl != null;
            }
コード例 #18
0
        /// <summary>
        /// 加入链表
        /// </summary>
        /// <param name="startpos">开始位</param>
        /// <param name="endpos">结束位</param>
        /// <param name="state">处理状态</param>
        private void AddToLink(int startpos, int endpos, EDFAState state)
        {
            string temp  = null;
            IToken token = null;

            if (endpos >= 0 && startpos >= 0 && endpos >= startpos)
            {
                temp = _expression.Substring(startpos, endpos - startpos + 1);

                //字符串去除两边引号
                if (state == EDFAState.CharStr)
                {
                    if (temp.Length == 2)
                    {
                        temp = string.Empty;
                    }
                    else
                    {
                        temp = temp.Substring(1, temp.Length - 1).Substring(0, temp.Length - 2).Replace("\\\"", "\"");;
                    }
                }
                else
                {
                    //去除标记中的空格换行符等 例如:8 6 转换为 86
                    temp = temp.Replace(" ", "").Replace("\r\n", "").Replace("\t", "");
                }

                switch (state)
                {
                case EDFAState.IntStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint, Convert.ToInt32(temp)), startpos);

                    break;

                case EDFAState.DoubleStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble, Convert.ToDouble(temp)), startpos);

                    break;

                case EDFAState.CharStr:
                    token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <string>(EDataType.Dstring, temp), startpos);
                    break;

                case EDFAState.OperatorStr:
                    bool          flag = true;
                    EOperatorType type = EOperatorType.Plus;
                    switch (temp)
                    {
                    case "(":
                        type = EOperatorType.LeftParen;
                        break;

                    case ")":
                        type = EOperatorType.RightParen;
                        break;

                    case "+":
                    case "-":
                        if (_link_OP.Tail != null && ((_link_OP.Tail.Token.Type == ETokenType.token_operand) ||
                                                      (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                       ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.RightParen)))
                        {
                            if (temp == "-")
                            {
                                type = EOperatorType.Minus;
                            }
                            else
                            {
                                type = EOperatorType.Plus;
                            }
                        }
                        else
                        {
                            if (temp == "-")
                            {
                                type = EOperatorType.Negative;
                            }
                            else
                            {
                                type = EOperatorType.Positive;
                            }
                        }
                        break;

                    case "*":
                        type = EOperatorType.Multiply;
                        break;

                    case "/":
                        type = EOperatorType.Divide;
                        break;

                    case "%":
                        type = EOperatorType.Mod;
                        break;

                    case "<":
                        type = EOperatorType.LessThan;
                        break;

                    case ">":
                        if (_link_OP.Tail != null && (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                      ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.LessThan))
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.NotEqual];
                            flag = false;
                        }
                        else
                        {
                            type = EOperatorType.GreaterThan;
                        }
                        break;

                    case "=":
                        if (_link_OP.Tail != null && (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                                      ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.LessThan))
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.LessEqual];
                            flag = false;
                        }
                        else if (_link_OP.Tail.Token.Type == ETokenType.token_operator &&
                                 ((TOKEN <Operator>)_link_OP.Tail.Token).Tag.Type == EOperatorType.GreaterThan)
                        {
                            ((TOKEN <Operator>)_link_OP.Tail.Token).Tag = Define.Operators[EOperatorType.GreaterEqual];
                            flag = false;
                        }
                        else
                        {
                            type = EOperatorType.Equal;
                        }
                        break;

                    default:
                        break;
                    }

                    if (flag)
                    {
                        token = new TOKEN <Operator>(ETokenType.token_operator, Define.Operators[type], startpos);
                    }

                    break;

                default:
                    break;
                }

                if (token != null)
                {
                    _link_OP.Add(new TOKENLink(token));
                }
            }
        }
コード例 #19
0
        //private static bool MemberCompare(object left, object right)
        //{
        //    if (Object.ReferenceEquals(left, right))
        //        return true;

        //    if (left == null || right == null)
        //        return false;

        //    Type type = left.GetType();
        //    if (type != right.GetType())
        //        return false;

        //    if (left as ValueType != null)
        //        return left.Equals(right);

        //    if (left as IEnumerable != null)
        //    {
        //        IEnumerator rightEnumerator = (right as IEnumerable).GetEnumerator();
        //        rightEnumerator.Reset();
        //        foreach (object leftItem in left as IEnumerable)
        //        {
        //            if (!rightEnumerator.MoveNext())
        //            {
        //                return false;
        //            }
        //            else
        //            {
        //                if (!MemberCompare(leftItem, rightEnumerator.Current))
        //                    return false;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Debug.Check(false);
        //    }

        //    return true;
        //}

        public static bool Compare <T>(T left, T right, EOperatorType comparisonType)
        {
            Type type = typeof(T);

            if (Utils.IsCustomStructType(type))
            {
                //bool bEqual = MemberCompare(left, right);
                bool bEqual = Operator <T> .MemberEqual(left, right);

                switch (comparisonType)
                {
                case EOperatorType.E_EQUAL: return(bEqual);

                case EOperatorType.E_NOTEQUAL: return(!bEqual);
                }
            }
            else if (Utils.IsArrayType(type))
            {
                //bool bEqual = MemberCompare(left, right);
                bool bEqual = Operator <T> .ItemEqual(left, right);

                switch (comparisonType)
                {
                case EOperatorType.E_EQUAL: return(bEqual);

                case EOperatorType.E_NOTEQUAL: return(!bEqual);
                }
            }
            else if (Utils.IsStringType(type) || type == typeof(bool))
            {
                switch (comparisonType)
                {
                case EOperatorType.E_EQUAL: return(Operator <T> .Equal(left, right));

                case EOperatorType.E_NOTEQUAL: return(Operator <T> .NotEqual(left, right));
                }
            }
            else if (Utils.IsEnumType(type) || type == typeof(char))
            {
                int iLeft  = Convert.ToInt32(left);
                int iRight = Convert.ToInt32(right);

                switch (comparisonType)
                {
                case EOperatorType.E_EQUAL: return(Operator <int> .Equal(iLeft, iRight));

                case EOperatorType.E_NOTEQUAL: return(Operator <int> .NotEqual(iLeft, iRight));

                case EOperatorType.E_GREATER: return(Operator <int> .GreaterThan(iLeft, iRight));

                case EOperatorType.E_GREATEREQUAL: return(Operator <int> .GreaterThanOrEqual(iLeft, iRight));

                case EOperatorType.E_LESS: return(Operator <int> .LessThan(iLeft, iRight));

                case EOperatorType.E_LESSEQUAL: return(Operator <int> .LessThanOrEqual(iLeft, iRight));
                }
            }
            else
            {
                switch (comparisonType)
                {
                case EOperatorType.E_EQUAL: return(Operator <T> .Equal(left, right));

                case EOperatorType.E_NOTEQUAL: return(Operator <T> .NotEqual(left, right));

                case EOperatorType.E_GREATER: return(Operator <T> .GreaterThan(left, right));

                case EOperatorType.E_GREATEREQUAL: return(Operator <T> .GreaterThanOrEqual(left, right));

                case EOperatorType.E_LESS: return(Operator <T> .LessThan(left, right));

                case EOperatorType.E_LESSEQUAL: return(Operator <T> .LessThanOrEqual(left, right));
                }
            }

            Debug.Check(false);
            return(false);
        }
コード例 #20
0
ファイル: SyntaxAnalyzer.cs プロジェクト: tomyqg/SemiGC
        /// <summary>
        /// 检查操作符与操作数的类型匹配
        /// </summary>
        /// <param name="startLink"></param>
        /// <param name="endLink"></param>
        private IOperand OperatorEvalAnalyze(TOKENLink startLink, TOKENLink endLink)
        {
            //先检查再进行后缀表达式转换
            TokenEnvirAnalyze(startLink, endLink);

            TOKENLink postfixLink = _toolBox.InfixToPostfix(startLink, endLink);
            TOKENLink link_new    = null;
            IToken    token       = null;

            while (postfixLink.Next != null)
            {
                postfixLink = postfixLink.Next;

                if (postfixLink.Token.Type == ETokenType.token_operator)
                {
                    link_new = null;
                    token    = null;
                    EOperatorType type = ((TOKEN <Operator>)postfixLink.Token).Tag.Type;
                    switch (type)
                    {
                    case EOperatorType.Positive:      //正
                    case EOperatorType.Negative:      //负
                        IOperand operand = ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag;
                        if (operand.Type == EDataType.Ddouble || operand.Type == EDataType.Dint)
                        {
                            token = postfixLink.Prev.Token;
                        }
                        else
                        {
                            throw new Exception(string.Format("Error! 运算符“{0}”无法应用于“{2}”类型的操作数(索引:{1})",
                                                              ((TOKEN <Operator>)postfixLink.Token).Tag.Value, postfixLink.Token.Index.ToString(), operand.Type.ToString()));
                        }

                        break;

                    case EOperatorType.Plus:
                    case EOperatorType.Minus:
                    case EOperatorType.Multiply:
                    case EOperatorType.Divide:
                    case EOperatorType.Mod:
                        if ((((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dstring ||
                             ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dstring) &&
                            (type == EOperatorType.Plus || type == EOperatorType.Minus))
                        {
                            token = new TOKEN <IOperand>(ETokenType.token_operand,
                                                         new Operand <string>(EDataType.Dstring, ""), postfixLink.Token.Index);
                        }
                        else if ((((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddouble ||
                                  ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dint) &&
                                 (((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddouble ||
                                  ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dint))
                        {
                            if ((((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddouble ||
                                 ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddouble) ||
                                (type == EOperatorType.Divide || type == EOperatorType.Mod))
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <double>(EDataType.Ddouble, 0), postfixLink.Token.Index);
                            }
                            else
                            {
                                token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <int>(EDataType.Dint, 0), postfixLink.Token.Index);
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format("Error! 运算符“{0}”无法应用于“{2}”和“{3}”类型的操作数(索引:{1})",
                                                              ((TOKEN <Operator>)postfixLink.Token).Tag.Value, postfixLink.Token.Index.ToString(),
                                                              ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type.ToString(),
                                                              ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type.ToString()));
                        }

                        break;

                    case EOperatorType.LessThan:
                    case EOperatorType.GreaterThan:
                    case EOperatorType.Equal:
                    case EOperatorType.NotEqual:
                    case EOperatorType.GreaterEqual:
                    case EOperatorType.LessEqual:

                        if (((((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddouble ||
                              ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dint) &&
                             (((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddouble ||
                              ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dint)) ||
                            (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Ddatetime &&
                             ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Ddatetime) ||
                            (((((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dstring &&
                               ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dstring) ||
                              (((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type == EDataType.Dbool &&
                               ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type == EDataType.Dbool)) &&
                             (type == EOperatorType.Equal || type == EOperatorType.NotEqual)))
                        {
                            token = new TOKEN <IOperand>(ETokenType.token_operand, new Operand <bool>(EDataType.Dbool, true), postfixLink.Token.Index);
                        }
                        else
                        {
                            throw new Exception(string.Format("Error! 运算符“{0}”无法应用于“{2}”和“{3}”类型的操作数(索引:{1})",
                                                              ((TOKEN <Operator>)postfixLink.Token).Tag.Value, postfixLink.Token.Index.ToString(),
                                                              ((TOKEN <IOperand>)postfixLink.Prev.Prev.Token).Tag.Type.ToString(),
                                                              ((TOKEN <IOperand>)postfixLink.Prev.Token).Tag.Type.ToString()));
                        }

                        break;

                    default:
                        break;
                    }

                    if (token != null)
                    {
                        link_new = new TOKENLink(token);

                        link_new.Next = postfixLink.Next;
                        if (postfixLink.Next != null)
                        {
                            postfixLink.Next.Prev = link_new;
                        }

                        if (((TOKEN <Operator>)postfixLink.Token).Tag.Dimension == 1)
                        {
                            //一元操作符
                            if (postfixLink.Prev.Prev != null)
                            {
                                link_new.Prev = postfixLink.Prev.Prev;
                                postfixLink.Prev.Prev.Next = link_new;
                            }
                        }
                        else if (((TOKEN <Operator>)postfixLink.Token).Tag.Dimension == 2)
                        {
                            //二元操作符
                            if (postfixLink.Prev.Prev.Prev != null)
                            {
                                link_new.Prev = postfixLink.Prev.Prev.Prev;
                                postfixLink.Prev.Prev.Prev.Next = link_new;
                            }
                        }

                        postfixLink = link_new;
                    }
                } //end if
            }     //end while

            return(((TOKEN <IOperand>)postfixLink.Token).Tag);
        }
コード例 #21
0
        public PainCodeLine SetCodeLine(PainCodeLine compiledLine, CodeLine line)
        {
            IList <Char> lineTrimmed = line.
                                       TrimStart().
                                       ToArray();

            IList <Char>  lineBody     = line;
            EOperatorType operatorType = EOperatorType.NONE;

            // IF: wykrycie definicji IF'a
            if (lineTrimmed.Count > str_if.Length &&
                StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_if, true) &&
                Char.IsWhiteSpace(lineTrimmed[str_if.Length]))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.IF;

                lineBody = lineTrimmed.
                           Substring2(str_if.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // WHILE: wykrycie definicji WHILE'a
            else if (lineTrimmed.Count > str_while.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_while, true) &&
                     Char.IsWhiteSpace(lineTrimmed[str_while.Length]))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.WHILE;

                lineBody = lineTrimmed.
                           Substring2(str_while.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // ELSE: wykrycie definicji ELSE'a
            else if (lineTrimmed.Count >= str_else.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_else, true))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELSE;

                lineBody = lineTrimmed.
                           Substring2(str_else.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // ELIF: wykrycie definicji ELIF'a
            else if (lineTrimmed.Count > str_elif.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_elif, true) &&
                     Char.IsWhiteSpace(lineTrimmed[str_elif.Length]))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELIF;

                lineBody = lineTrimmed.
                           Substring2(str_elif.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // RETURN: wykrycie definicji RETURN'a
            else if (lineTrimmed.Count > str_return.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_return, true) &&
                     Char.IsWhiteSpace(lineTrimmed[str_return.Length]))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.RETURN;

                lineBody = lineTrimmed.
                           Substring2(str_return.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // TRY: wykrycie definicji TRY'a
            else if (lineTrimmed.Count > str_try.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_try, true) /*&&
                                                                                               * Char.IsWhiteSpace(lineTrimmed[str_try.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.TRY;

                lineBody = lineTrimmed.
                           Substring2(str_try.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // CATCH: wykrycie definicji CATCH'a
            else if (lineTrimmed.Count > str_catch.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_catch, true) /*&&
                                                                                                 * Char.IsWhiteSpace(lineTrimmed[str_catch.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.CATCH;

                lineBody = lineTrimmed.
                           Substring2(str_catch.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // FINALLY: wykrycie definicji FINALLY'a
            else if (lineTrimmed.Count > str_finally.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_finally, true) /*&&
                                                                                                   * Char.IsWhiteSpace(lineTrimmed[str_finally.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.FINALLY;

                lineBody = lineTrimmed.
                           Substring2(str_finally.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }
            // THROW: wykrycie definicji THROW'a
            else if (lineTrimmed.Count > str_throw.Length &&
                     StringHelper.StrEquals(lineTrimmed.TrimStart().ToArray(), str_throw, true) /*&&
                                                                                                 * Char.IsWhiteSpace(lineTrimmed[str_THROW.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.THROW;

                lineBody = lineTrimmed.
                           Substring2(str_throw.Length).
                           TrimStart().
                           ToList();

                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                lineBody.TrimEnd(':');
            }

            ExpressionGroup expressionGroup = TokenizerInvariant.I.
                                              Compile(lineBody);

            if (compiledLine == null)
            {
                compiledLine = new PainCodeLine();
            }

            compiledLine.Code            = line.ToString2();
            compiledLine.ExpressionGroup = expressionGroup;
            compiledLine.OperatorType    = operatorType;
            compiledLine.IsLineEmpty     = lineTrimmed.Count == 0;
            compiledLine.Depth          += GetDepth(lineBody);

            return(compiledLine);
        }
コード例 #22
0
ファイル: Compiler.cs プロジェクト: b-y-t-e/DynLan
        /*public DynLanCodeLine GetCodeLine(Int32 Depth, CodeLine line, CodeLine nextLine)
         * {
         *  return SetCodeLine(null, Depth, line, nextLine);
         * }*/

        /*public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, Int32 Depth, String line)
         * {
         *  return SetCodeLine(compiledLine, Depth, new CodeLine(line));
         * }*/

        public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, CodeLine line, CodeLine nextLine, ref Int32 Depth, ref int CharIndex)
        {
            Int32 orgDepth = Depth;

            IList <Char> lineTrimmed = Linq2.ToArray(
                StringHelper.TrimStart(
                    StringHelper.TrimEnd(line)));

            IList <Char>  lineBody     = line;
            EOperatorType operatorType = EOperatorType.NONE;

            // IF: wykrycie definicji IF'a
            if (//lineTrimmed.Count > str_if.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_if, true, true) /* &&
                                                                                                                 * Char.IsWhiteSpace(lineTrimmed[str_if.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.IF;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_if.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("IF body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("IF body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // WHILE: wykrycie definicji WHILE'a
            else if (//lineTrimmed.Count > str_while.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_while, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_while.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.WHILE;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_while.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("WHILE body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("WHILE body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // ELSE: wykrycie definicji ELSE'a
            else if (// lineTrimmed.Count >= str_else.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_else, true, true))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELSE;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_else.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count > 0)
                {
                    throw new Exception("ELSE body must be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("ELSE body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // ELIF: wykrycie definicji ELIF'a
            else if (// lineTrimmed.Count > str_elif.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_elif, true, true) /*&&
                                                                                                                   * Char.IsWhiteSpace(lineTrimmed[str_elif.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELIF;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_elif.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("ELIF body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("ELIF body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // RETURN: wykrycie definicji RETURN'a
            else if (// lineTrimmed.Count > str_return.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_return, true, true) /*&&
                                                                                                                     * Char.IsWhiteSpace(lineTrimmed[str_return.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.RETURN;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_return.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // RETURN: wykrycie definicji RETURN'a

            /*else if (// lineTrimmed.Count >= str_return.Length &&
             *         StringHelper.StartsWith(lineTrimmed.TrimStart().ToArray(), str_return, true, true))
             * {
             *  Int32 depth = GetDepth(line);
             *  operatorType = EOperatorType.RETURN;
             *
             *  lineBody = lineTrimmed.
             *      Substring2(str_return.Length).
             *      TrimStart().
             *      ToList();
             *
             #if SPACES_FOR_DEPTH
             *  for (int i = 0; i < depth; i++)
             *      lineBody.Insert(0, ' ');
             *  // lineBody.TrimEnd(':');
             #endif
             * }*/
            // RETURN: wykrycie definicji PASS'a
            else if (//(lineTrimmed.Count == str_pass.Length || (lineTrimmed.Count > str_pass.Length && Char.IsWhiteSpace(lineTrimmed[str_pass.Length])))
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_pass, true, true))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.PASS;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_pass.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // TRY: wykrycie definicji TRY'a
            else if (// lineTrimmed.Count > str_try.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_try, true, true) /*&&
                                                                                                                  * Char.IsWhiteSpace(lineTrimmed[str_try.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.TRY;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_try.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("TRY body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // CATCH: wykrycie definicji CATCH'a
            else if (// lineTrimmed.Count > str_catch.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_catch, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_catch.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.CATCH;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_catch.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("CATCH body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // FINALLY: wykrycie definicji FINALLY'a
            else if (// lineTrimmed.Count > str_finally.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_finally, true, true) /*&&
                                                                                                                      * Char.IsWhiteSpace(lineTrimmed[str_finally.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.FINALLY;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_finally.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("FINALLY body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // THROW: wykrycie definicji THROW'a
            else if (lineTrimmed.Count > str_throw.Length &&
                     StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_throw, true, true) /*&&
                                                                                                                         * Char.IsWhiteSpace(lineTrimmed[str_THROW.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.THROW;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_throw.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // BREAK: wykrycie definicji BREAK'a
            else if (// lineTrimmed.Count > str_break.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_break, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_break.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.BREAK;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_break.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }

            ExpressionGroup expressionGroup = TokenizerInvariant.I.
                                              Compile(lineBody);

            if (compiledLine == null)
            {
                compiledLine = new DynLanCodeLine();
            }

            compiledLine.Code            = StringHelper.ToString2(line);
            compiledLine.ExpressionGroup = expressionGroup;
            compiledLine.OperatorType    = operatorType;
            compiledLine.IsLineEmpty     = lineTrimmed.Count == 0;

#if !SPACES_FOR_DEPTH
            compiledLine.Depth = orgDepth;
#else
            compiledLine.Depth += GetDepth(lineBody);
#endif

            return(compiledLine);
        }
コード例 #23
0
            public virtual bool load(List <property_t> properties)
            {
                for (int i = 0; i < properties.Count; ++i)
                {
                    property_t p = properties[i];

                    if (p.name == "Opl")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opl = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opl = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Opr1")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr1 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr1 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Operator")
                    {
                        this.m_operator = OperationUtils.ParseOperatorType(p.value);
                    }
                    else if (p.name == "Opr2")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr2 = AgentMeta.ParseProperty(p.value);
                            }
                            else
                            {
                                this.m_opr2 = AgentMeta.ParseMethod(p.value);
                            }
                        }
                    }
                }

                return(this.m_opl != null);
            }
コード例 #24
0
            public virtual bool load(List <property_t> properties)
            {
                string opr2TypeName   = null;
                string comparatorName = null;

                for (int i = 0; i < properties.Count; ++i)
                {
                    property_t p = properties[i];
                    if (p.name == "Mode")
                    {
                        switch (p.value)
                        {
                        case "Condition":
                            this.m_mode = TransitionMode.Condition;
                            break;

                        case "Success":
                            this.m_mode = TransitionMode.Success;
                            break;

                        case "Failure":
                            this.m_mode = TransitionMode.Failure;
                            break;

                        case "End":
                            this.m_mode = TransitionMode.End;
                            break;
                        }
                    }
                    else if (p.name == "Opl")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                string typeName = null;
                                this.m_opl = Condition.LoadRight(p.value, ref typeName);
                            }
                            else
                            {
                                //method
                                this.m_opl_m = Action.LoadMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Opr1")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                string typeName = null;
                                this.m_opr1 = Condition.LoadRight(p.value, ref typeName);
                            }
                            else
                            {
                                //method
                                this.m_opr1_m = Action.LoadMethod(p.value);
                            }
                        }
                    }
                    else if (p.name == "Operator")
                    {
                        comparatorName = p.value;

                        switch (p.value)
                        {
                        case "Invalid":
                            this.m_operator = EOperatorType.E_INVALID;
                            break;

                        case "Assign":
                            this.m_operator = EOperatorType.E_ASSIGN;
                            break;

                        case "Add":
                            this.m_operator = EOperatorType.E_ADD;
                            break;

                        case "Sub":
                            this.m_operator = EOperatorType.E_SUB;
                            break;

                        case "Mul":
                            this.m_operator = EOperatorType.E_MUL;
                            break;

                        case "Div":
                            this.m_operator = EOperatorType.E_DIV;
                            break;

                        case "Equal":
                            this.m_operator = EOperatorType.E_EQUAL;
                            break;

                        case "NotEqual":
                            this.m_operator = EOperatorType.E_NOTEQUAL;
                            break;

                        case "Greater":
                            this.m_operator = EOperatorType.E_GREATER;
                            break;

                        case "Less":
                            this.m_operator = EOperatorType.E_LESS;
                            break;

                        case "GreaterEqual":
                            this.m_operator = EOperatorType.E_GREATEREQUAL;
                            break;

                        case "LessEqual":
                            this.m_operator = EOperatorType.E_LESSEQUAL;
                            break;
                        }
                    }
                    else if (p.name == "Opr2")
                    {
                        if (StringUtils.IsValidString(p.value))
                        {
                            int pParenthesis = p.value.IndexOf('(');

                            if (pParenthesis == -1)
                            {
                                this.m_opr2 = Condition.LoadRight(p.value, ref opr2TypeName);
                            }
                            else
                            {
                                //method
                                this.m_opr2_m = Action.LoadMethod(p.value);
                            }
                        }
                    }
                    else
                    {
                        //Debug.Check(0, "unrecognised property %s", p.name);
                    }
                }

                // compare
                if (this.m_operator >= EOperatorType.E_EQUAL && this.m_operator <= EOperatorType.E_LESSEQUAL)
                {
                    if (!string.IsNullOrEmpty(comparatorName) && (this.m_opl != null || this.m_opl_m != null) &&
                        (this.m_opr2 != null || this.m_opr2_m != null))
                    {
                        this.m_comparator = Condition.Create(comparatorName, this.m_opl, this.m_opl_m, this.m_opr2, this.m_opr2_m);
                    }
                }

                return(this.m_opl != null);
            }