コード例 #1
0
ファイル: LogicOpNode.cs プロジェクト: oisbel/TigerCompiler
        public void CheckSemantic(Scope scope, List<Error> errors, string op)
        {
            //coumpruebo sintacticamente el primer operando
            LeftOperand.CheckSemantic(scope, errors);

            if (RigthOperand != null)
            {
                //compruebo q el tipo de retorno del operando izq sea int
                if (LeftOperand.ReturnType!= null &&LeftOperand.ReturnType.BaseType.Name != "int")
                    errors.Add(new Error(Row, Col, string.Format("The left operand in \"{0}\" operator must be return an int", op)));

                //coumpruebo sintacticamente el segundo operando
                RigthOperand.CheckSemantic(scope, errors);

                //compruebo q el tipo de retorno sea int
                if (RigthOperand.ReturnType != null && RigthOperand.ReturnType.BaseType.Name != "int")
                    errors.Add(new Error(Row, Col, string.Format("The rigth operand in \"{0}\" operator must be return an int", op)));

                // pongo su tipo de retorno en int
                ReturnType = new TypeInfo("int",null,TypeDecl.Base);
            }
            else
            {
                ReturnType = LeftOperand.ReturnType;
            }
        }
コード例 #2
0
ファイル: Info.cs プロジェクト: oisbel/TigerCompiler
 public TypeInfo(string name, TypeInfo parent, TypeDecl decl)
 {
     Name = name;
         Parent = parent;
         typedecl = decl;//para saber si es una de las decl del enum
 }
コード例 #3
0
ファイル: Info.cs プロジェクト: oisbel/TigerCompiler
 public FunctionInfo(string id, TypeInfo type, List<Parameter> parameters)
 {
     Id = id; ReturnType = type; Parameters = parameters;
 }
コード例 #4
0
ファイル: Info.cs プロジェクト: oisbel/TigerCompiler
 public VarInfo(string id, TypeInfo type)
 {
     Id = id; Type = type;
 }
コード例 #5
0
ファイル: EqualityNode.cs プロジェクト: oisbel/TigerCompiler
        public void CheckSemantic(Scope scope, List<Error> errors, string op)
        {
            string type = "";
            string type1 = "";

            //comprobando la semantica del primer operando
            LeftOperand.CheckSemantic(scope, errors);

            if (RigthOperand != null)
            {
                //guardo el tipo de retorno del operando izquierdo
                if (LeftOperand.ReturnType!= null && LeftOperand.ReturnType.BaseType.Name == "int") type = "int";
                //sino veo si es string
                else if (LeftOperand.ReturnType != null && LeftOperand.ReturnType.BaseType.Name == "string") type = "string";
                //sino veo si es un record
                else if (LeftOperand.ReturnType != null && LeftOperand.ReturnType.typedecl == TypeDecl.Record) type = "record";
                //sino veo si es array
                else if (LeftOperand.ReturnType != null && LeftOperand.ReturnType.typedecl == TypeDecl.Array) type = "array";
                //sino veo si es nil
                else if (LeftOperand.ReturnType != null && LeftOperand.ReturnType.BaseType.Name == "nil") type = "nil";
                //sino lanzo un error porq solo puede ser uno de estos tipos
                else
                    errors.Add(new Error(Row, Col, string.Format("The left operand in \"{0}\" operator must be one of the defined types", op)));

                //compruebo la semantica del segundo operando
                RigthOperand.CheckSemantic(scope, errors);

                //gurado el tipo de retorno del segundo operando
                if (RigthOperand.ReturnType != null && RigthOperand.ReturnType.BaseType.Name == "int") type1 = "int";
                //sino veo si es string
                else if (RigthOperand.ReturnType != null &&  RigthOperand.ReturnType.BaseType.Name == "string") type1 = "string";
                //sino veo si es un record
                else if (RigthOperand.ReturnType != null && RigthOperand.ReturnType.typedecl == TypeDecl.Record) type1 = "record";
                //sino veo si es array
                else if (RigthOperand.ReturnType != null && RigthOperand.ReturnType.typedecl == TypeDecl.Array) type1 = "array";
                //sino veo si es nil
                else if (RigthOperand.ReturnType != null && RigthOperand.ReturnType.BaseType.Name == "nil") type1 = "nil";
                //sino lanzo un error porq solo puede ser estos dos tipos
                else
                    errors.Add(new Error(Row, Col, string.Format("The rigth operand in \"{0}\" must be one of the defined types", op)));

                //si son de distintos tipos y ninguno es nil lanzo un error
                if (type1 != type)
                {
                    if(type != "nil" && type1 != "nil")
                        errors.Add(new Error(Row, Col, string.Format("The left and rigth operand in \"{0}\" operator may be either of the same type", op)));
                }
                //si son del mismo tipo pero nil lanzo un error
                else if (type == "nil")
                {
                    errors.Add(new Error(Row, Col, string.Format("The left and rigth operand in \"{0}\" operator can't be nill", op)));
                }

                // actualizo su tipo de retorno en int
                ReturnType = new TypeInfo("int", null, TypeDecl.Base);

            }
            else
            {
                ReturnType = LeftOperand.ReturnType;
            }
        }