Beispiel #1
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            AnalyCorrect = true;
            if (LeftExp == null && RightExp != null)
            {
                ExpUnary unexp = new ExpUnary(this.ExpContext, OpToken, RightExp);
                var      exp   = unexp.Analy();
                return(exp);
            }
            else if (LeftExp == null && RightExp == null)
            {
                Errorf(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.Text);
            }
            OpKind   = OpToken.Kind;
            LeftExp  = AnalySubExp(LeftExp);
            RightExp = AnalySubExp(RightExp);

            if (RightExp == null)
            {
                Errorf(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.Text);
            }
            else
            {
                this.AnalyCorrect = this.LeftExp.AnalyCorrect && RightExp.AnalyCorrect && this.AnalyCorrect;
                if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect)
                {
                    ZType ltype = LeftExp.RetType;
                    ZType rtype = RightExp.RetType;
                    if (ZTypeUtil.IsVoid(ltype) || ZTypeUtil.IsVoid(rtype))
                    {
                        Errorf(OpToken.Position, "没有结果的表达式无法进行'{0}'运算", OpToken.ToCode());
                    }
                    else
                    {
                        OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype, rtype);
                        if (OpMethod != null)
                        {
                            RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType;
                        }
                        else
                        {
                            Errorf(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode());
                        }
                    }
                }
                else
                {
                    this.RetType = ZLangBasicTypes.ZOBJECT;
                }
            }
            //AnalyResultLocal();
            IsAnalyed = true;
            return(this);
        }
Beispiel #2
0
        public override Exp Analy( )
        {
            if (LeftExp == null && RightExp != null)
            {
                ExpUnary unexp = new ExpUnary(OpToken, RightExp, this.ExpContext);
                //unexp.SetContext(this.ExpContext);
                var exp = unexp.Analy();
                return(exp);
            }
            else if (LeftExp == null && RightExp == null)
            {
                ErrorE(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.GetText());
                //AnalyResult = false;
            }

            OpKind   = OpToken.Kind;
            LeftExp  = AnalySubExp(LeftExp);
            RightExp = AnalySubExp(RightExp);

            if (RightExp == null)
            {
                ErrorE(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.GetText());
                //AnalyResult = false;
            }
            else
            {
                if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect)
                {
                    ZType ltype = LeftExp.RetType;
                    ZType rtype = RightExp.RetType;

                    OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype.SharpType, rtype.SharpType);
                    if (OpMethod != null)
                    {
                        RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType;
                    }
                    else
                    {
                        ErrorE(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode());
                    }
                }
            }
            return(this);
        }