public override Exp Analy( ) { OpKind = OpToken.Kind; if (OpKind != TokenKind.ADD && OpKind != TokenKind.SUB) { ErrorE(OpToken.Position, "运算符'{0}'缺少表达式", OpToken.GetText()); //return null; } RightExp = AnalySubExp(RightExp);// RightExp.Analy(); if (RightExp.AnalyCorrect) { this.RetType = RightExp.RetType; Type stype = RetType.SharpType; if (stype != typeof(int) && stype != typeof(float) && stype != typeof(double) && stype != typeof(decimal)) { ErrorE(RightExp.Postion, "不能进行'{0}'运算", OpToken.GetText()); //return null; } } if (OpKind == TokenKind.ADD) { return(RightExp); } else { return(this); } }
public override Exp Analy(AnalyExpContext context) { base.Analy(context); var symbols = this.AnalyExpContext.Symbols; OpKind = OpToken.Kind; if(OpKind!= TokenKind.ADD && OpKind!= TokenKind.SUB) { errorf(OpToken.Postion, "运算符'{0}'缺少表达式", OpToken.GetText()); return null; } RightExp = RightExp.Analy(context);//RightExp = AnalyExp(RightExp); if(RightExp==null) { TrueAnalyed = false; return null; } Type rtype = RightExp.RetType; RetType = rtype; if(rtype!= typeof(int)&& rtype!= typeof(float) && rtype!= typeof(double) && rtype != typeof(decimal)) { errorf(RightExp.Postion,"不能进行'{0}'运算",OpToken.GetText()); return null; } if (OpKind == TokenKind.ADD) { return RightExp; } return this; }
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); }