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()); }
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)); }
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); }
public override void GetNestedFields(Dictionary <string, VarExp> nestedField) { LeftExp.GetNestedFields(nestedField); RightExp.GetNestedFields(nestedField); }
public override void SetParent(Exp parentExp) { ParentExp = parentExp; LeftExp.SetParent(this); RightExp.SetParent(this); }
public override void AnalyDim() { AnalyResultLocal(); LeftExp.AnalyDim(); RightExp.AnalyDim(); }