Example #1
0
        public override string ToCode()
        {
            StringBuilder buf = new StringBuilder();

            buf.Append(LeftExp != null ? LeftExp.ToString() : "");
            buf.Append(OpToken != null ? OpToken.ToCode() : "");
            buf.Append(RightExp != null ? RightExp.ToString() : "");
            return(buf.ToString());
        }
Example #2
0
 private void EmitSubject( )
 {
     if (SubjectIsStruct())
     {
         EmitAsVar();
     }
     else
     {
         LeftExp.Emit();
     }
 }
Example #3
0
        public void Evaluate(string message, string author)
        {
            var        context    = new Context(message, author, _lobbyController);
            Expression expression = null;

            if (int.TryParse(message, out int receivedNumber))
            {
                var playerMove = Enums.ParsePlayerMove(receivedNumber);
                switch (playerMove)
                {
                case Enums.PlayerAction.Up:
                    expression = new UpExp();
                    break;

                case Enums.PlayerAction.Down:
                    expression = new DownExp();
                    break;

                case Enums.PlayerAction.Left:
                    expression = new LeftExp();
                    break;

                case Enums.PlayerAction.Right:
                    expression = new RightExp();
                    break;

                default:
                    return;
                }
            }
            else if (message.Equals(StringLiterals.StartGame))
            {
                expression = new GameStartExp();
            }
            else if (message.ToLower().StartsWith("kick "))
            {
                context.message = context.message.Remove(0, 5);
                expression      = new KickExp();
            }

            if (expression == null)
            {
                return;
            }

            expression.Evaluate(context);
        }
        /// <summary>
        /// Builds the <c>CalcOperation</c>.
        /// </summary>
        public CalcOperation Build()
        {
            if (Operator == null)
            {
                throw new InvalidOperationException("CalcOperations cannot be built without an operator.");
            }

            string operType = Operator.GetType().Name;

            // Postfix and Binary operators require a left operand.
            if (!(Operator is CLPrefixOperator))
            {
                if (LeftExp != null)
                {
                    Left = LeftExp.Build();
                }
                if (LeftObj == null)
                {
                    throw new InvalidOperationException(operType + " requires a left-side operand.");
                }
            }
            else
            {
                LeftObj = null;
            }

            // Prefix and Binary operators require a left operand.
            if (!(Operator is CLPostfixOperator))
            {
                if (RightExp != null)
                {
                    Right = RightExp.Build();
                }
                if (RightObj == null)
                {
                    throw new InvalidOperationException(operType + " requires a right-side operand.");
                }
            }
            else
            {
                RightObj = null;
            }

            return(new CalcOperation(LeftObj, Operator, RightObj));
        }
Example #5
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;

            OpKind = OpToken.Kind;

            if (RightExp == null)
            {
                errorf(OpToken.Postion, "运算符'{0}'右边缺少运算元素", OpToken.GetText());
                return(null);
            }
            else if (LeftExp == null && RightExp != null)
            {
                UnaryExp unexp = new UnaryExp(OpToken, RightExp);
                var      exp   = unexp.Analy(context);
                return(exp);
            }

            LeftExp  = LeftExp.Analy(context);  //LeftExp = AnalyExp(LeftExp);
            RightExp = RightExp.Analy(context); //RightExp = AnalyExp(RightExp);

            if (LeftExp == null || RightExp == null)
            {
                TrueAnalyed = false;
                return(null);
            }

            Type ltype = LeftExp.RetType;
            Type rtype = RightExp.RetType;

            OpMethod = BinExpUtil.GetCalcMethod(OpKind, ltype, rtype);
            if (OpMethod != null)
            {
                RetType = OpMethod.ReturnType;
            }

            if (RetType == null)
            {
                error("两种类型无法进行'" + OpToken.ToCode() + "'运算");
            }
            return(this);
        }
Example #6
0
 public override void GetNestedFields(Dictionary <string, VarExp> nestedField)
 {
     LeftExp.GetNestedFields(nestedField);
     RightExp.GetNestedFields(nestedField);
 }
Example #7
0
 public override void SetParent(Exp parentExp)
 {
     ParentExp = parentExp;
     LeftExp.SetParent(this);
     RightExp.SetParent(this);
 }
Example #8
0
 public override void AnalyDim()
 {
     AnalyResultLocal();
     LeftExp.AnalyDim();
     RightExp.AnalyDim();
 }