public override Word GetMember(MemberSegment memberSegment)
        {
            if (Visitor == null)
            {
                throw new Exception("Tiene que inicializar visitor con InitVisitor antes de usar cualquier GetMember");
            }
            Word result;

            switch (memberSegment.GetSegmentType())
            {
            case SegmentType.Identifier:
                result = Visitor.GetGlobalAttribute((IdentifierSegment)memberSegment);
                if (ErrorHelper.IsError(result))                                                    //se modifica el mensaje
                {
                    return(ErrorFactory.BadAttributeError(this, (IdentifierSegment)memberSegment)); //Chapuz alto: es el unico caso en el que no se retoran el mismo error de un result o se modifica el mismo. I.e. No se puede decir que todo MyError puede ser reportado
                }
                return(result);

            case SegmentType.Procedure:
                result = Visitor.InvokeProcedure((ProcedureSegment)memberSegment);
                if (ErrorHelper.IsError(result))    //se modifica el mensaje
                {
                    return(ErrorFactory.BadProcedureError(this, (ProcedureSegment)memberSegment));
                }
                return(result);

            case SegmentType.Index:
                return(ErrorFactory.BadIndexError(this, (IndexSegment)memberSegment));

            default:
                throw new Exception("Member segment no valido para ClassInstance.GetMember" + memberSegment.GetSegmentType());
            }
        }
Пример #2
0
        public override Word GetMember(MemberSegment memberSegment)
        {
            switch (memberSegment.GetSegmentType())
            {
            case SegmentType.Identifier:
                return(ErrorFactory.BadAttributeError(this, (IdentifierSegment)memberSegment));

            case SegmentType.Index:
                return(ErrorFactory.BadIndexError(this, (IndexSegment)memberSegment));

            case SegmentType.Procedure:
                return(ErrorFactory.BadProcedureError(this, (ProcedureSegment)memberSegment));

            default:
                throw new Exception("tipo de member segment no valido: " + memberSegment.GetSegmentType().ToString());
            }
        }
Пример #3
0
        public override Word GetMember(MemberSegment memberSegment)
        {
            IdentifierSegment identSegment;
            IndexSegment      indexSegment;
            ProcedureSegment  functionSegment;

            switch (memberSegment.GetSegmentType())
            {
            case SegmentType.Identifier:
                identSegment = (IdentifierSegment)memberSegment;
                return(ErrorFactory.BadAttributeError(this, (IdentifierSegment)memberSegment));

            case SegmentType.Index:
                indexSegment = (IndexSegment)memberSegment;
                var pyObj     = indexSegment.Index;
                var pyObjType = pyObj.GetMyType();
                if (pyObjType != TypeConstants.INT && pyObjType != TypeConstants.CHAR)
                {
                    return(ErrorFactory.BadIndexError(this, indexSegment));
                }
                int index;
                if (pyObjType == TypeConstants.INT)
                {
                    index = ((MyInt)pyObj).Int;
                }
                else
                {
                    index = ((MyChar)pyObj).CharValue;
                }

                if (index >= Array.Length || index < 0)
                {
                    return(ErrorFactory.OutOfBounds(this, index, 0, Array.Length - 1));
                }

                return(Array[index]);

            case SegmentType.Procedure:
                functionSegment = (ProcedureSegment)memberSegment;
                return(ErrorFactory.BadAttributeError(this, (IdentifierSegment)memberSegment));

            default:
                throw new Exception("tipo de member segment no valido");
            }
        }