Beispiel #1
0
 public MiniPascalType NodeType(Scope Current)
 {
     Type = variable.Type;
     if (reference.ArrayIndex != null)
     {
         MiniPascalType refType = reference.ArrayIndex.NodeType(Current);
         if (!refType.Equals(MiniPascalType.Integer))
         {
             throw new InvalidArrayIndexTypeException(refType);
         }
         if (Type.SimpleType.Equals(SimpleType.Boolean))
         {
             return(MiniPascalType.Boolean);
         }
         else if (Type.SimpleType.Equals(SimpleType.Integer))
         {
             return(MiniPascalType.Integer);
         }
         else if (Type.SimpleType.Equals(SimpleType.String))
         {
             return(MiniPascalType.String);
         }
         else if (Type.SimpleType.Equals(SimpleType.Real))
         {
             return(MiniPascalType.Real);
         }
     }
     return(Type);
 }
Beispiel #2
0
 public Procedure(Identifier Identifier, Parameters Parameters, ScopedProgram Block, MiniPascalType Type)
 {
     identifier      = Identifier;
     this.Parameters = Parameters;
     block           = Block;
     ReturnType      = Type;
 }
Beispiel #3
0
        private DeclarationStatement VariableDeclaration()
        {
            if (Accept(Symbol.Variable))
            {
                List <Identifier> ids = new List <Identifier>();
                do
                {
                    Identifier identifier = Identifier();
                    if (identifier == null)
                    {
                        throw new SyntaxException(expIdentifier, current);
                    }
                    ids.Add(identifier);
                } while (Accept(Symbol.Comma));

                Require(Symbol.Colon);
                MiniPascalType type = ReadType();
                if (type == null)
                {
                    throw new SyntaxException(expType, current);
                }
                return(new DeclarationStatement(ids, type));
            }
            return(null);
        }
Beispiel #4
0
 public void EmitIR(CILEmitter Emitter)
 {
     for (int i = 0; i < toPrint.Count; i++)
     {
         IExpression    expr     = toPrint.Expression(i);
         MiniPascalType exprType = toPrint.Type(i);
         expr.EmitIR(Emitter, false);
         Emitter.CallPrint(exprType);
     }
 }
Beispiel #5
0
        public void CheckType(Scope Current)
        {
            MiniPascalType condType = condition.NodeType(Current);

            if (!condType.Equals(MiniPascalType.Boolean))
            {
                throw new TypeMismatchException(MiniPascalType.Boolean, condType);
            }
            thenStatement.CheckType(Current);
            elseStatement?.CheckType(Current);
        }
Beispiel #6
0
        private Variable ReadVariable()
        {
            bool isReference = Accept(Symbol.Variable);

            Identifier identifier = Identifier();

            if (identifier == null)
            {
                throw new SyntaxException(expIdentifier, current);
            }

            Require(Symbol.Colon);
            MiniPascalType type = ReadType();

            if (type == null)
            {
                throw new SyntaxException(expType, current);
            }
            return(new Variable(identifier, type, isReference));
        }
Beispiel #7
0
 private Procedure ReadFunction()
 {
     if (Accept(Symbol.Function))
     {
         Identifier ident = Identifier();
         Require(Symbol.ClosureOpen);
         Parameters parameters = ReadParameters();
         Require(Symbol.ClosureClose);
         Require(Symbol.Colon);
         MiniPascalType type = ReadType();
         if (type == null)
         {
             throw new SyntaxException(expType, current);
         }
         Require(Symbol.SemiColon);
         ScopedProgram block = Block();
         block.AddParameters(parameters);
         return(new Procedure(ident, parameters, block, type));
     }
     return(null);
 }
Beispiel #8
0
        public MiniPascalType NodeType(Scope Current)
        {
            arguments.CheckType(Current);
            ToCall = Current.Procedure(toBeCalled);
            if (arguments.Count != ToCall.Parameters.DeclaredCount)
            {
                throw new InvalidParameterCountException(ToCall.Parameters.DeclaredCount, arguments.Count);
            }
            Parameters parameters = ToCall.Parameters;

            for (int i = 0; i < arguments.Count; i++)
            {
                MiniPascalType argType = arguments.Type(i);
                MiniPascalType parType = parameters.At(i).Type;
                if (!argType.Equals(parType))
                {
                    throw new TypeMismatchException(parType, argType);
                }
            }
            Type = ToCall.ReturnType;
            return(Type);
        }
        public void CheckType(Scope Current)
        {
            MiniPascalType type          = variable.Type;
            MiniPascalType assigmentType = assigment.NodeType(Current);

            if (!assigmentType.Equals(type))
            {
                if (variable.Type.IsArray && !assigmentType.IsArray)
                {
                    if (!variable.Type.SimpleType.Equals(assigmentType.SimpleType))
                    {
                        throw new InvalidSimpleTypeException(assigmentType.SimpleType, variable.Type.SimpleType);
                    }
                }
                else
                {
                    throw new TypeMismatchException(type, assigmentType);
                }
            }
            if (reference.ArrayIndex != null)
            {
                if (assigmentType.IsArray)
                {
                    throw new ArrayAssigmentExpection(type.SimpleType, assigmentType);
                }
                MiniPascalType indexType = reference.ArrayIndex.NodeType(Current);
                if (!indexType.Equals(MiniPascalType.Integer))
                {
                    throw new InvalidArrayIndexTypeException(indexType);
                }
            }
            else if (reference.ArrayIndex == null && variable.Type.IsArray && !assigmentType.IsArray)
            {
                throw new InvalidArrayIndexTypeException(null);
            }
        }
Beispiel #10
0
 public Variable(Identifier Identifier, MiniPascalType Type, bool IsReference)
 {
     this.Identifier  = Identifier;
     this.Type        = Type;
     this.IsReference = IsReference;
 }