Beispiel #1
0
 public override string ToCode()
 {
     StringBuilder buf = new StringBuilder();
     buf.Append(OpToken != null ? OpToken.ToCode() : "");
     buf.Append(RightExp != null ? RightExp.ToString() : "");
     return buf.ToString();
 }
Beispiel #2
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);
        }