/// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo = findCargo(trackingId);
            var voyage = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if(voyage == null)
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
                }
                else
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode);
                }
            }
            catch(Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
示例#2
0
 private static bool IsUnary(OperatorCode code)
 {
     return(code == OperatorCode.BoolNot ||
            code == OperatorCode.IntNeg ||
            code == OperatorCode.FloatNeg ||
            code == OperatorCode.VectorOp60);
 }
示例#3
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((OperatorCode.GetHashCode() * 397) ^ (int)Number);
     }
 }
示例#4
0
        public static IOperandTerm ReduceBinaryTerm(OperatorCode op, IOperandTerm left, IOperandTerm right)
        {
            OperatorMethod method = null;

            if ((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(Int64)))
            {
                if (binaryIntIntDic.ContainsKey(op))
                {
                    method = binaryIntIntDic[op];
                }
            }
            else if ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(string)))
            {
                if (binaryStrStrDic.ContainsKey(op))
                {
                    method = binaryStrStrDic[op];
                }
            }
            else if (((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(string))) ||
                     ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(Int64))))
            {
                if (op == OperatorCode.Mult)
                {
                    method = binaryMultIntStr;
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new IOperandTerm[] { left, right }));
            }
            string errMes = "";

            if (left.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型と";
            }
            else if (left.GetOperandType() == typeof(string))
            {
                errMes += "文字列型と";
            }
            else
            {
                errMes += "不定型と";
            }
            if (right.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型の";
            }
            else if (right.GetOperandType() == typeof(string))
            {
                errMes += "文字列型の";
            }
            else
            {
                errMes += "不定型の";
            }
            errMes += "演算に二項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }
示例#5
0
        private static CaseExpression reduceCaseExpression(WordCollection wc)
        {
            CaseExpression ret = new CaseExpression();
            IdentifierWord id  = wc.Current as IdentifierWord;

            if ((id != null) && (id.Code.Equals("IS", Config.SCVariable)))
            {
                wc.ShiftNext();
                ret.CaseType = CaseExpressionType.Is;
                OperatorWord opWT = wc.Current as OperatorWord;
                if (opWT == null)
                {
                    throw new CodeEE("ISキーワードの後に演算子がありません");
                }

                OperatorCode op = opWT.Code;
                if (!OperatorManager.IsBinary(op))
                {
                    throw new CodeEE("ISキーワードの後の演算子が2項演算子ではありません");
                }
                wc.ShiftNext();
                ret.Operator = op;
                ret.LeftTerm = reduceTerm(wc, false, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.LeftTerm == null)
                {
                    throw new CodeEE("ISキーワードの後に式がありません");
                }
                Type type = ret.LeftTerm.GetOperandType();
                return(ret);
            }
            ret.LeftTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
            if (ret.LeftTerm == null)
            {
                throw new CodeEE("CASEの引数は省略できません");
            }
            id = wc.Current as IdentifierWord;
            if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
            {
                ret.CaseType = CaseExpressionType.To;
                wc.ShiftNext();
                ret.RightTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.RightTerm == null)
                {
                    throw new CodeEE("TOキーワードの後に式がありません");
                }
                id = wc.Current as IdentifierWord;
                if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
                {
                    throw new CodeEE("TOキーワードが2度使われています");
                }
                if (ret.LeftTerm.GetOperandType() != ret.RightTerm.GetOperandType())
                {
                    throw new CodeEE("TOキーワードの前後の型が一致していません");
                }
                return(ret);
            }
            ret.CaseType = CaseExpressionType.Normal;
            return(ret);
        }
示例#6
0
 public static string GetOperatorText(OperatorCode code)
 {
     if (OperatorTextTable.ContainsKey(code))
     {
         return(OperatorTextTable[code]);
     }
     return(string.Empty);
 }
示例#7
0
 public InstructionLine(ScriptPosition thePosition, FunctionIdentifier functionIdentifier, OperatorCode assignOP, WordCollection dest, StringStream theArgPrimitive)
 {
     base.position     = thePosition;
     func              = functionIdentifier;
     AssignOperator    = assignOP;
     assigndest        = dest;
     this.argprimitive = theArgPrimitive;
 }
示例#8
0
            private void reduceTernary(IOperandTerm left, IOperandTerm right, OperatorCode op)
            {
                OperatorCode newOp   = (OperatorCode)stack.Pop();
                IOperandTerm newLeft = (IOperandTerm)stack.Pop();

                IOperandTerm newTerm = OperatorMethodManager.ReduceTernaryTerm(newOp, newLeft, left, right);

                stack.Push(newTerm);
            }
示例#9
0
            private void reduceUnary()
            {
                //if (stack.Count < 2)
                //    throw new ExeEE("不正な時期の呼び出し");
                IOperandTerm operand = (IOperandTerm)stack.Pop();
                OperatorCode op      = (OperatorCode)stack.Pop();
                IOperandTerm newTerm = OperatorMethodManager.ReduceUnaryTerm(op, operand);

                stack.Push(newTerm);
            }
示例#10
0
 protected static string OperatorString(OperatorCode @operator, int value)
 {
     return(@operator switch
     {
         OperatorCode.Equals => $"{value}",
         OperatorCode.GreaterThan => $"more than {value}",
         OperatorCode.GreaterThanOrEqualTo => $"{value} or more",
         OperatorCode.LessThan => $"fewer than {value}",
         OperatorCode.LessThanOrEqualTo => $"{value} or fewer",
         _ => throw new NotImplementedException(),
     });
示例#11
0
 public static bool TokenIsOperator(Token token, OperatorCode opCpde)
 {
     if (token.Type != TokenType.Operator)
     {
         return(false);
     }
     if ((OperatorCode)(token.Value) != opCpde)
     {
         return(false);
     }
     return(true);
 }
示例#12
0
            private int lastPriority()
            {
                if (stack.Count < 3)
                {
                    return(-1);
                }
                object       temp     = (object)stack.Pop();
                OperatorCode opCode   = (OperatorCode)stack.Peek();
                int          priority = OperatorManager.GetPriority(opCode);

                stack.Push(temp);
                return(priority);
            }
示例#13
0
        public static IOperandTerm ReduceUnaryTerm(OperatorCode op, IOperandTerm o1)
        {
            OperatorMethod method = null;

            if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
            {
                VariableTerm var = o1 as VariableTerm;
                if (var == null)
                {
                    throw new CodeEE("変数以外をインクリメントすることはできません");
                }
                if (var.Identifier.IsConst)
                {
                    throw new CodeEE("変更できない変数をインクリメントすることはできません");
                }
            }
            if (o1.GetOperandType() == typeof(Int64))
            {
                if (op == OperatorCode.Plus)
                {
                    return(o1);
                }
                OperatorMethod operator_method = null;
                if (unaryDic.TryGetValue(op, out operator_method))
                {
                    method = operator_method;
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new IOperandTerm[] { o1 }));
            }
            string errMes = "";

            if (o1.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型";
            }
            else if (o1.GetOperandType() == typeof(string))
            {
                errMes += "文字列型";
            }
            else
            {
                errMes += "不定型";
            }
            errMes += "に単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }
示例#14
0
 public static string ToOperatorString(OperatorCode op)
 {
     if (op == OperatorCode.NULL)
     {
         return("");
     }
     foreach (var pair in opDictionary)
     {
         if (op == pair.Value)
         {
             return(pair.Key);
         }
     }
     return("");
 }
示例#15
0
        private void ChangeStateMessage(OperatorCode code)
        {
            if (this.statusStrip1.InvokeRequired)
            {
                Action <OperatorCode> action = new Action <OperatorCode>(ChangeStateMessage);
                this.Invoke(action, code);
                return;
            }

            switch (code)
            {
            case OperatorCode.Opening:
                this.statueMessageLabel.Text = "正在打开网络服务 ...";
                break;

            case OperatorCode.Opened:
                this.statueMessageLabel.Text = "网络服务已经就绪 .";
                break;

            case OperatorCode.Closing:
                this.statueMessageLabel.Text = "正在停止网络服务 ...";
                break;

            case OperatorCode.Closed:
                this.statueMessageLabel.Text = "网络服务已经停止 .";
                this.statueProgressbar.Value = 0;
                break;

            case OperatorCode.Received:
                this.statueMessageLabel.Text = "接收到网络协议(UDP)数据报,开始解析数据报 .";
                this.statueProgressbar.Value = 0;
                this.statueProgressbar.Value = 50;
                break;

            case OperatorCode.Analyzed:
                this.statueMessageLabel.Text = "接收网络协议(UDP)数据报,并解析 .";
                this.statueProgressbar.Value = 100;
                break;

            case OperatorCode.Error:
                this.statueMessageLabel.Text = "发生错误,重新接收数据 .";
                break;

            default:
                this.statueMessageLabel.Text = "以就绪,等待操作 .";
                break;
            }
        }
示例#16
0
        public static IOperandTerm ReduceTernaryTerm(OperatorCode op, IOperandTerm o1, IOperandTerm o2, IOperandTerm o3)
        {
            OperatorMethod method = null;

            if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(Int64)) && (o3.GetOperandType() == typeof(Int64)))
            {
                method = ternaryIntIntInt;
            }
            else if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(string)) && (o3.GetOperandType() == typeof(string)))
            {
                method = ternaryIntStrStr;
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new IOperandTerm[] { o1, o2, o3 }));
            }
            throw new CodeEE("三項演算子の使用法が不正です");
        }
示例#17
0
        public bool NextTokenIsOperator(OperatorCode opCode)
        {
            Token token = PreviewNextToken();

            if (token == null)
            {
                return(false);
            }
            if (token.Type != TokenType.Operator)
            {
                return(false);
            }
            if (((OperatorCode)token.Value) != opCode)
            {
                return(false);
            }
            return(true);
        }
示例#18
0
        public static IOperandTerm ReduceUnaryAfterTerm(OperatorCode op, IOperandTerm o1)
        {
            OperatorMethod method = null;

            if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
            {
                var var = o1 as VariableTerm;
                if (var == null)
                {
                    throw new CodeEE("変数以外をインクリメントすることはできません");
                }
                if (var.Identifier.IsConst)
                {
                    throw new CodeEE("変更できない変数をインクリメントすることはできません");
                }
            }
            if (o1.GetOperandType() == typeof(long))
            {
                if (unaryAfterDic.ContainsKey(op))
                {
                    method = unaryAfterDic[op];
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new[] { o1 }));
            }
            var errMes = "";

            if (o1.GetOperandType() == typeof(long))
            {
                errMes += "数値型";
            }
            else if (o1.GetOperandType() == typeof(string))
            {
                errMes += "文字列型";
            }
            else
            {
                errMes += "不定型";
            }
            errMes += "に後置単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }
        public void registerHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                          VoyageNumber voyageNumber, UnLocode unLocode,
                                          HandlingActivityType type, OperatorCode operatorCode)
        {
            // Using a factory to create a HandlingEvent (aggregate). This is where
            // it is determined wether the incoming data, the attempt, actually is capable
            // of representing a real handling handlingEvent.
            var handlingEvent = handlingEventFactory.createHandlingEvent(
              completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
            );

            // Store the new handling handlingEvent, which updates the persistent
            // state of the handling handlingEvent aggregate (but not the cargo aggregate -
            // that happens asynchronously!)
            handlingEventRepository.store(handlingEvent);

            // Publish a system event
            systemEvents.notifyOfHandlingEvent(handlingEvent);

            LOG.Info("Registered handling event: " + handlingEvent);
        }
示例#20
0
        public void registerHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                          VoyageNumber voyageNumber, UnLocode unLocode,
                                          HandlingActivityType type, OperatorCode operatorCode)
        {
            // Using a factory to create a HandlingEvent (aggregate). This is where
            // it is determined wether the incoming data, the attempt, actually is capable
            // of representing a real handling handlingEvent.
            var handlingEvent = handlingEventFactory.createHandlingEvent(
                completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
                );

            // Store the new handling handlingEvent, which updates the persistent
            // state of the handling handlingEvent aggregate (but not the cargo aggregate -
            // that happens asynchronously!)
            handlingEventRepository.store(handlingEvent);

            // Publish a system event
            systemEvents.notifyOfHandlingEvent(handlingEvent);

            LOG.Info("Registered handling event: " + handlingEvent);
        }
示例#21
0
            private void reduceLastThree()
            {
                //if (stack.Count < 2)
                //    throw new ExeEE("不正な時期の呼び出し");
                IOperandTerm right = (IOperandTerm)stack.Pop();//後から入れたほうが右側
                OperatorCode op    = (OperatorCode)stack.Pop();
                IOperandTerm left  = (IOperandTerm)stack.Pop();

                if (OperatorManager.IsTernary(op))
                {
                    if (stack.Count > 1)
                    {
                        reduceTernary(left, right, op);
                        return;
                    }
                    throw new CodeEE("式の数が不足しています");
                }

                IOperandTerm newTerm = OperatorMethodManager.ReduceBinaryTerm(op, left, right);

                stack.Push(newTerm);
            }
示例#22
0
        /// <summary>
        /// 失敗したらCodeEE。OperatorManagerには頼らない
        /// "="の時、OperatorCode.Assignmentを返す。"=="の時はEqual
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public static OperatorCode ReadAssignmentOperator(StringStream st)
        {
            OperatorCode ret = OperatorCode.NULL;
            char         cur = st.Current;

            st.ShiftNext();
            char next = st.Current;

            switch (cur)
            {
            case '+':
                if (next == '+')
                {
                    ret = OperatorCode.Increment;
                }
                else if (next == '=')
                {
                    ret = OperatorCode.Plus;
                }
                break;

            case '-':
                if (next == '-')
                {
                    ret = OperatorCode.Decrement;
                }
                else if (next == '=')
                {
                    ret = OperatorCode.Minus;
                }
                break;

            case '*':
                if (next == '=')
                {
                    ret = OperatorCode.Mult;
                }
                break;

            case '/':
                if (next == '=')
                {
                    ret = OperatorCode.Div;
                }
                break;

            case '%':
                if (next == '=')
                {
                    ret = OperatorCode.Mod;
                }
                break;

            case '=':
                if (next == '=')
                {
                    ret = OperatorCode.Equal;
                    break;
                }
                return(OperatorCode.Assignment);

            case '\'':
                if (next == '=')
                {
                    ret = OperatorCode.AssignmentStr;
                    break;
                }
                throw new CodeEE("\"\'\"は代入演算子として認識できません");

            case '<':
                if (next == '<')
                {
                    st.ShiftNext();
                    if (st.Current == '=')
                    {
                        ret = OperatorCode.LeftShift;
                        break;
                    }
                    throw new CodeEE("'<'は代入演算子として認識できません");
                }
                break;

            case '>':
                if (next == '>')
                {
                    st.ShiftNext();
                    if (st.Current == '=')
                    {
                        ret = OperatorCode.RightShift;
                        break;
                    }
                    throw new CodeEE("'>'は代入演算子として認識できません");
                }
                break;

            case '|':
                if (next == '=')
                {
                    ret = OperatorCode.BitOr;
                }
                break;

            case '&':
                if (next == '=')
                {
                    ret = OperatorCode.BitAnd;
                }
                break;

            case '^':
                if (next == '=')
                {
                    ret = OperatorCode.BitXor;
                }
                break;
            }
            if (ret == OperatorCode.NULL)
            {
                throw new CodeEE("'" + cur + "'は代入演算子として認識できません");
            }
            st.ShiftNext();
            return(ret);
        }
示例#23
0
 private static bool IsUnary(OperatorCode code)
 {
     return code == OperatorCode.BoolNot ||
            code == OperatorCode.IntNeg ||
            code == OperatorCode.FloatNeg ||
            code == OperatorCode.VectorOp60;
 }
示例#24
0
        private static string GetOperator(OperatorCode code)
        {
            switch (code)
            {
                case OperatorCode.IntAdd:
                case OperatorCode.FloatAdd:
                case OperatorCode.StringAdd:
                case OperatorCode.TimeAddTime:
                case OperatorCode.TimeAddFloat:
                    return "+";

                case OperatorCode.IntSubtract:
                case OperatorCode.IntNeg:
                case OperatorCode.FloatSubtract:
                case OperatorCode.FloatNeg:
                    return "-";

                case OperatorCode.IntMultiply:
                case OperatorCode.FloatMultiply:
                    return "*";

                case OperatorCode.IntDivide:
                case OperatorCode.FloatDivide:
                    return "/";

                case OperatorCode.IntEqual:
                case OperatorCode.FloatEqual:
                case OperatorCode.UniqueIdEqual:
                    return "==";

                case OperatorCode.IntNotEqual:
                case OperatorCode.FloatNotEqual:
                case OperatorCode.UniqueIdNotEqual:
                    return "!=";

                case OperatorCode.IntLess:
                case OperatorCode.FloatLess:
                    return "<";

                case OperatorCode.IntLessEqual:
                case OperatorCode.FloatLessEqual:
                    return "<=";

                case OperatorCode.IntGreater:
                case OperatorCode.FloatGreater:
                    return ">";

                case OperatorCode.IntGreaterEqual:
                case OperatorCode.FloatGreaterEqual:
                    return ">=";

                case OperatorCode.IntAssignAdd:
                case OperatorCode.FloatAssignAdd:
                    return "+=";

                case OperatorCode.IntAssignSubtract:
                case OperatorCode.FloatAssignSubtract:
                    return "-=";

                case OperatorCode.IntAssignMultiply:
                case OperatorCode.FloatAssignMultiply:
                    return "*=";

                case OperatorCode.FloatAssignDivide:
                    return "/=";

                case OperatorCode.BoolAnd:
                    return "&&";

                case OperatorCode.BoolOr:
                    return "||";

                case OperatorCode.BoolNot:
                    return "!";

                case OperatorCode.IntAnd:
                    return "&";

                case OperatorCode.IntOr:
                    return "|";

                case OperatorCode.IntAssignOr:
                    return "|=";

                case OperatorCode.FloatOp25:
                    return "<op25>";

                case OperatorCode.ByteOp41:
                    return "<op41>";

                case OperatorCode.ByteOp48:
                    return "<op48>";

                case OperatorCode.VectorOp60:
                    return "<op60>";

                case OperatorCode.VectorOp61:
                    return "<op61>";

                case OperatorCode.VectorOp62:
                    return "<op62>";

                case OperatorCode.VectorOp65:
                    return "<op65>";

                case OperatorCode.VectorOp66:
                    return "<op66>";

                case OperatorCode.VectorOp71:
                    return "<op71>";

                case OperatorCode.VectorOp72:
                    return "<op72>";

                case OperatorCode.VectorOp75:
                    return "<op75>";

                case OperatorCode.VectorOp76:
                    return "<op76>";

                case OperatorCode.VectorOp77:
                    return "<op77>";

                case OperatorCode.TimeOp84:
                    return "<op84>";

                case OperatorCode.TimeOp85:
                    return "<op85>";
                
                case OperatorCode.TimeOp92:
                    return "<op92>";

                case OperatorCode.TimeOp93:
                    return "<op93>";

                case OperatorCode.TimeOp94:
                    return "<op94>";

                case OperatorCode.TimeOp95:
                    return "<op95>";

                case OperatorCode.TimeOp96:
                    return "<op96>";

                case OperatorCode.TimeOp97:
                    return "<op97>";

                case OperatorCode.TimeOp98:
                    return "<op98>";

                case OperatorCode.TimeOp100:
                    return "<op100>";

                case OperatorCode.TimeOp104:
                    return "<op104>";

                case OperatorCode.Op120:
                    return "<op120>";
                
                default:
                    return null;
            }
        }
示例#25
0
 public static IOperandTerm ReduceBinaryTerm(OperatorCode op, IOperandTerm left, IOperandTerm right)
 {
     OperatorMethod method = null;
     if ((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(Int64)))
     {
         if (binaryIntIntDic.ContainsKey(op))
             method = binaryIntIntDic[op];
     }
     else if ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(string)))
     {
         if (binaryStrStrDic.ContainsKey(op))
             method = binaryStrStrDic[op];
     }
     else if (((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(string)))
          || ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(Int64))))
     {
         if (op == OperatorCode.Mult)
             method = binaryMultIntStr;
     }
     if (method != null)
         return new FunctionMethodTerm(method, new IOperandTerm[] { left, right });
     string errMes = "";
         if (left.GetOperandType() == typeof(Int64))
             errMes += "数値型と";
         else if (left.GetOperandType() == typeof(string))
             errMes += "文字列型と";
         else
             errMes += "不定型と";
         if (right.GetOperandType() == typeof(Int64))
             errMes += "数値型の";
         else if (right.GetOperandType() == typeof(string))
             errMes += "文字列型の";
         else
             errMes += "不定型の";
         errMes += "演算に二項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
         throw new CodeEE(errMes);
 }
示例#26
0
 public static string ToOperatorString(OperatorCode op)
 {
     if (op == OperatorCode.NULL)
         return "";
     foreach(KeyValuePair<string, OperatorCode> pair in opDictionary)
     {
         if(op == pair.Value)
             return pair.Key;
     }
     return "";
 }
 public CardTypeCountCondition(int value, OperatorCode @operator, CardType cardType)
 {
     Value    = value;
     Operator = @operator;
     CardType = cardType;
 }
示例#28
0
 public static ResourceCountCondition ResourceCount(ResourceType resource, OperatorCode @operator, int value)
 => new ResourceCountCondition(value, @operator, resource);
示例#29
0
 public OperatorWord(OperatorCode op)
 {
     code = op;
 }
示例#30
0
文件: Word.cs 项目: yyx2684264/emuera
 public OperatorWord(OperatorCode op)
 {
     Code = op;
 }
示例#31
0
 public static IOperandTerm ReduceUnaryTerm(OperatorCode op, IOperandTerm o1)
 {
     OperatorMethod method = null;
     if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
     {
         VariableTerm var = o1 as VariableTerm;
         if (var == null)
             throw new CodeEE("変数以外をインクリメントすることはできません");
         if (var.Identifier.Readonly)
             throw new CodeEE("変更できない変数をインクリメントすることはできません");
     }
     if (o1.GetOperandType() == typeof(Int64))
     {
         if (op == OperatorCode.Plus)
             return o1;
         if (unaryDic.ContainsKey(op))
             method = unaryDic[op];
     }
     if(method != null)
         return new FunctionMethodTerm(method, new IOperandTerm[] { o1 });
     string errMes = "";
     if (o1.GetOperandType() == typeof(Int64))
         errMes += "数値型";
     else if (o1.GetOperandType() == typeof(string))
         errMes += "文字列型";
     else
         errMes += "不定型";
     errMes += "に単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
     throw new CodeEE(errMes);
 }
示例#32
0
        /// <summary>
        /// 解析器の本体
        /// </summary>
        /// <param name="wc"></param>
        /// <param name="allowKeywordTo">TOキーワードが見つかっても良いか</param>
        /// <param name="endWith">終端記号</param>
        /// <returns></returns>
        private static IOperandTerm reduceTerm(WordCollection wc, bool allowKeywordTo, TermEndWith endWith, VariableCode varCode)
        {
            TermStack stack = new TermStack();
            //int termCount = 0;
            int          ternaryCount = 0;
            OperatorCode formerOp     = OperatorCode.NULL;
            bool         varArg       = varCode != VariableCode.__NULL__;

            do
            {
                Word token = wc.Current;
                switch (token.Type)
                {
                case '\0':
                    goto end;

                case '"':                        //LiteralStringWT
                    stack.Add(((LiteralStringWord)token).Str);
                    break;

                case '0':                        //LiteralIntegerWT
                    stack.Add(((LiteralIntegerWord)token).Int);
                    break;

                case 'F':                        //FormattedStringWT
                    stack.Add(ToStrFormTerm((StrFormWord)token));
                    break;

                case 'A':                        //IdentifierWT
                {
                    string idStr = (((IdentifierWord)token).Code);
                    if (idStr.Equals("TO", Config.SCVariable))
                    {
                        if (allowKeywordTo)
                        {
                            goto end;
                        }
                        else
                        {
                            throw new CodeEE("TOキーワードはここでは使用できません");
                        }
                    }
                    else if (idStr.Equals("IS", Config.SCVariable))
                    {
                        throw new CodeEE("ISキーワードはここでは使用できません");
                    }
                    stack.Add(reduceIdentifier(wc, idStr, varCode));
                    continue;
                }

                case '=':                        //OperatorWT
                {
                    if (varArg)
                    {
                        throw new CodeEE("変数の引数の読み取り中に予期しない演算子を発見しました");
                    }
                    OperatorCode op = ((OperatorWord)token).Code;
                    if (op == OperatorCode.Assignment)
                    {
                        if ((endWith & TermEndWith.Assignment) == TermEndWith.Assignment)
                        {
                            goto end;
                        }
                        throw new CodeEE("式中で代入演算子'='が使われています(等価比較には'=='を使用してください)");
                    }

                    if (formerOp == OperatorCode.Equal || formerOp == OperatorCode.Greater || formerOp == OperatorCode.Less ||
                        formerOp == OperatorCode.GreaterEqual || formerOp == OperatorCode.LessEqual || formerOp == OperatorCode.NotEqual)
                    {
                        if (op == OperatorCode.Equal || op == OperatorCode.Greater || op == OperatorCode.Less ||
                            op == OperatorCode.GreaterEqual || op == OperatorCode.LessEqual || op == OperatorCode.NotEqual)
                        {
                            ParserMediator.Warn("(構文上の注意)比較演算子が連続しています。", GlobalStatic.Process.GetScaningLine(), 0, false, false);
                        }
                    }
                    stack.Add(op);
                    formerOp = op;
                    if (op == OperatorCode.Ternary_a)
                    {
                        ternaryCount++;
                    }
                    else if (op == OperatorCode.Ternary_b)
                    {
                        if (ternaryCount > 0)
                        {
                            ternaryCount--;
                        }
                        else
                        {
                            throw new CodeEE("対応する'?'のない'#'です");
                        }
                    }
                    break;
                }

                case '(':
                    wc.ShiftNext();
                    IOperandTerm inTerm = reduceTerm(wc, false, TermEndWith.RightParenthesis, VariableCode.__NULL__);
                    if (inTerm == null)
                    {
                        throw new CodeEE("かっこ\"(\"~\")\"の中に式が含まれていません");
                    }
                    stack.Add(inTerm);
                    if (wc.Current.Type != ')')
                    {
                        throw new CodeEE("対応する')'のない'('です");
                    }
                    //termCount++;
                    wc.ShiftNext();
                    continue;

                case ')':
                    if ((endWith & TermEndWith.RightParenthesis) == TermEndWith.RightParenthesis)
                    {
                        goto end;
                    }
                    throw new CodeEE("構文解釈中に予期しない記号'" + token.Type + "'を発見しました");

                case ']':
                    if ((endWith & TermEndWith.RightBracket) == TermEndWith.RightBracket)
                    {
                        goto end;
                    }
                    throw new CodeEE("構文解釈中に予期しない記号'" + token.Type + "'を発見しました");

                case ',':
                    if ((endWith & TermEndWith.Comma) == TermEndWith.Comma)
                    {
                        goto end;
                    }
                    throw new CodeEE("構文解釈中に予期しない記号'" + token.Type + "'を発見しました");

                case 'M':
                    throw new ExeEE("マクロ解決失敗");

                default:
                    throw new CodeEE("構文解釈中に予期しない記号'" + token.Type + "'を発見しました");
                }
                //termCount++;
                wc.ShiftNext();
            } while (!varArg);
end:
            if (ternaryCount > 0)
            {
                throw new CodeEE("'?'と'#'の数が正しく対応していません");
            }
            return(stack.ReduceAll());
        }
示例#33
0
 /// <summary>
 ///     大きい方が優先度が高い。 '&' < '+' < '*'等
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static int GetPriority(OperatorCode type)
 {
     return((int)(type & OperatorCode.__PRIORITY_MASK__));
 }
示例#34
0
 public static bool IsUnary(OperatorCode type)
 {
     return ((type & OperatorCode.__UNARY__) == OperatorCode.__UNARY__);
 }
示例#35
0
 public static bool IsUnaryAfter(OperatorCode type)
 {
     return((type & OperatorCode.__UNARY_AFTER__) == OperatorCode.__UNARY_AFTER__);
 }
示例#36
0
            private void reduceTernary(IOperandTerm left, IOperandTerm right, OperatorCode op)
            {
                OperatorCode newOp = (OperatorCode)stack.Pop();
                IOperandTerm newLeft = (IOperandTerm)stack.Pop();

                IOperandTerm newTerm = OperatorMethodManager.ReduceTernaryTerm(newOp, newLeft, left, right);
                stack.Push(newTerm);
            }
示例#37
0
        //public  OperatorCode Operation { get; set; }
        //public double Result { get; set; }
        //public  double TextBoxNumber { get; set; }

        public string SetOperator(TextBox text, double result, Double textBoxNumber, OperatorCode ops)
        {
            string calculatedValue = "";


            switch (ops)
            {
            case OperatorCode.ADDITION:
                result          = textBoxNumber + float.Parse(text.Text);
                calculatedValue = result.ToString();

                break;

            case OperatorCode.SUBTRATION:
                result          = textBoxNumber - float.Parse(text.Text);
                calculatedValue = result.ToString();
                break;

            case OperatorCode.MULTIPLICATION:
                result          = textBoxNumber * float.Parse(text.Text);
                calculatedValue = result.ToString();
                break;

            case OperatorCode.DIVISION:
                result          = textBoxNumber / float.Parse(text.Text);
                calculatedValue = result.ToString();
                break;

            case OperatorCode.COSINE:

                double rad = textBoxNumber * (Math.PI / 180);
                calculatedValue = Math.Cos(rad).ToString();

                break;

            case OperatorCode.SINE:

                double sinRad = textBoxNumber * (Math.PI / 180);
                calculatedValue = Math.Sin(sinRad).ToString();

                break;


            case OperatorCode.TANGENT:

                double tanRad = textBoxNumber * (Math.PI / 180);

                calculatedValue = Math.Tan(tanRad).ToString();

                break;

            case OperatorCode.POWER:

                double power = double.Parse(text.Text);
                calculatedValue = Math.Pow(textBoxNumber, power).ToString();
                break;

            default:
                break;
            }

            return(calculatedValue);
        }
示例#38
0
 public static bool IsUnaryAfter(OperatorCode type)
 {
     return ((type & OperatorCode.__UNARY_AFTER__) == OperatorCode.__UNARY_AFTER__);
 }
示例#39
0
 public static IOperandTerm ReduceTernaryTerm(OperatorCode op, IOperandTerm o1, IOperandTerm o2, IOperandTerm o3)
 {
     OperatorMethod method = null;
     if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(Int64)) && (o3.GetOperandType() == typeof(Int64)))
         method = ternaryIntIntInt;
     else if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(string)) && (o3.GetOperandType() == typeof(string)))
         method = ternaryIntStrStr;
     if (method != null)
         return new FunctionMethodTerm(method, new IOperandTerm[] { o1, o2, o3 });
     throw new CodeEE("三項演算子の使用法が不正です");
 }
示例#40
0
 public void Add(OperatorCode op)
 {
     if (state == 2 || state == 3)
     {
         throw new CodeEE("式が異常です");
     }
     if (state == 0)
     {
         if (!OperatorManager.IsUnary(op))
         {
             throw new CodeEE("式が異常です");
         }
         stack.Push(op);
         if (op == OperatorCode.Plus || op == OperatorCode.Minus || op == OperatorCode.BitNot)
         {
             state = 2;
         }
         else
         {
             state = 3;
         }
         return;
     }
     if (state == 1)
     {
         //後置単項演算子の場合は特殊処理へ
         if (OperatorManager.IsUnaryAfter(op))
         {
             if (hasAfter)
             {
                 hasAfter = false;
                 throw new CodeEE("後置の単項演算子が複数存在しています");
             }
             if (hasBefore)
             {
                 hasBefore = false;
                 throw new CodeEE("インクリメント・デクリメントを前置・後置両方同時に使うことはできません");
             }
             stack.Push(op);
             reduceUnaryAfter();
             //前置単項演算子が処理を待っている場合はここで解決
             if (waitAfter)
             {
                 reduceUnary();
             }
             hasBefore = false;
             hasAfter  = true;
             waitAfter = false;
             return;
         }
         if (!OperatorManager.IsBinary(op) && !OperatorManager.IsTernary(op))
         {
             throw new CodeEE("式が異常です");
         }
         //先に未解決の前置演算子解決
         if (waitAfter)
         {
             reduceUnary();
         }
         int priority = OperatorManager.GetPriority(op);
         //直前の計算の優先度が同じか高いなら還元。
         while (lastPriority() >= priority)
         {
             this.reduceLastThree();
         }
         stack.Push(op);
         state     = 0;
         waitAfter = false;
         hasBefore = false;
         hasAfter  = false;
         return;
     }
     throw new CodeEE("式が異常です");
 }
示例#41
0
 public void Add(OperatorCode op)
 {
     if (state == 2 || state == 3)
         throw new CodeEE("式が異常です");
     if (state == 0)
     {
         if (!OperatorManager.IsUnary(op))
             throw new CodeEE("式が異常です");
         stack.Push(op);
         if (op == OperatorCode.Plus || op == OperatorCode.Minus || op == OperatorCode.BitNot)
             state = 2;
         else
             state = 3;
         return;
     }
     if (state == 1)
     {
         //後置単項演算子の場合は特殊処理へ
         if (OperatorManager.IsUnaryAfter(op))
         {
             if (hasAfter)
             {
                 hasAfter = false;
                 throw new CodeEE("後置の単項演算子が複数存在しています");
             }
             if (hasBefore)
             {
                 hasBefore = false;
                 throw new CodeEE("インクリメント・デクリメントを前置・後置両方同時に使うことはできません");
             }
             stack.Push(op);
             reduceUnaryAfter();
             //前置単項演算子が処理を待っている場合はここで解決
             if (waitAfter)
                 reduceUnary();
             hasBefore = false;
             hasAfter = true;
             waitAfter = false;
             return;
         }
         if (!OperatorManager.IsBinary(op) && !OperatorManager.IsTernary(op))
             throw new CodeEE("式が異常です");
         //先に未解決の前置演算子解決
         if (waitAfter)
             reduceUnary();
         int priority = OperatorManager.GetPriority(op);
         //直前の計算の優先度が同じか高いなら還元。
         while (lastPriority() >= priority)
         {
             this.reduceLastThree();
         }
         stack.Push(op);
         state = 0;
         waitAfter = false;
         hasBefore = false;
         hasAfter = false;
         return;
     }
     throw new CodeEE("式が異常です");
 }
示例#42
0
 public static bool IsBinary(OperatorCode type)
 {
     return((type & OperatorCode.__BINARY__) == OperatorCode.__BINARY__);
 }
示例#43
0
 public Personal SetOperatorCode(OperatorCode operatorCode)
 {
     this.operatorCode = operatorCode;
     return this;
 }
示例#44
0
 public static bool IsTernary(OperatorCode type)
 {
     return((type & OperatorCode.__TERNARY__) == OperatorCode.__TERNARY__);
 }
示例#45
0
 /// <summary>
 /// 大きい方が優先度が高い。 '&' < '+' < '*'等
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static int GetPriority(OperatorCode type)
 {
     return (int)(type & OperatorCode.__PRIORITY_MASK__);
 }