Example #1
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            CheckIdentifier(scope, errors);
            if (scope.GetType(Identifier.Text).Type != TypesEnumeration.Array)
                errors.Add(SemanticError.WrongType(Identifier.Text, "Array", this));

            Identifier.ILName = string.Format("{0}Scope{1}", Identifier.Text, scope.CurrentScope);
            DefinedType.ILName = scope.GetILTypeName(DefinedType.Text);
        }
Example #2
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            //Verify if the array exist
            var varInfo = scope.GetVarInstance(this.ArrayIdentifier.Text);
            if (varInfo == null)
            {
                errors.Add(SemanticError.UndefinedVariableUsed(this.ArrayIdentifier.Text, this));
                return;
            }
            this.NextNested.CheckSemantics(varInfo.VariableType, scope, errors);
            ExpressionType = this.NextNested.ExpressionType;
            ArrayIdentifier.ILName = scope.GetILVarNames(ArrayIdentifier.Text);
            var arrayInfo = (ArrayInfo) scope.GetType(varInfo.VariableType);

            NextNested.Index.ILName = scope.GetILTypeName(arrayInfo.ItemsType);
            ILName = scope.GetILVarNames(ArrayIdentifier.Text);
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
Example #3
0
        public void CheckSemantics(string identifier, Scope scope, List<SemanticError> errors)
        {
            NestedNode curreNode = this;
            do
            {
                //check the field access
                var typeInfo = scope.GetType(identifier);
                if (curreNode is FieldNestedNode)
                {
                    //check if the type is record
                    if (typeInfo.Type != TypesEnumeration.Record)
                    {
                        errors.Add(SemanticError.WrongType("Record", typeInfo.Type.ToString(), this));
                        return;
                    }
                    var recordInfo = (RecordInfo)typeInfo;
                    var fieldNested  = (FieldNestedNode) curreNode;

                    var currentField = recordInfo.Parameters.FirstOrDefault(x => x.Identifier == fieldNested.FieldIdentifier.Text);
                    if (currentField == null)
                        errors.Add(SemanticError.InvalidFieldAccess(identifier,
                                                                    fieldNested.FieldIdentifier.Text, this));
                    else
                    {
                        fieldNested.FieldIdentifier.ILName = scope.GetILTypeName(identifier) + "." + fieldNested.FieldIdentifier.Text;
                        identifier = currentField.Type;
                    }
                }
                else
                {
                    //check if the type is an array
                    if (typeInfo.Type != TypesEnumeration.Array)
                    {
                        errors.Add(SemanticError.WrongType("Array", typeInfo.Type.ToString(), this));
                        return;
                    }
                    var arrayInfo = (ArrayInfo) typeInfo;
                    var arrayIndex = (IndexNestedNode) curreNode;
                    arrayIndex.CheckSemantics(scope, errors);
                    if (((IndexNestedNode)curreNode).Index.ExpressionType.Type != TypesEnumeration.Integer)
                        errors.Add(SemanticError.WrongType(((IndexNestedNode)curreNode).Index.ExpressionType.Name,"int",this));
                    else
                    {
                        identifier = arrayInfo.ItemsType;
                        //arrayIndex.Index.ILName = scope.GetILTypeName(identifier);
                    }

                    curreNode.ILName = scope.GetILTypeName(identifier);
                    //curreNode.ILName = scope.GetILTypeName(identifier) + "." + fieldNested.FieldIdentifier.Text;
                }
                curreNode = curreNode.NextNested;
            } while (curreNode != null);
            ExpressionType = scope.GetType(identifier);
        }
Example #4
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            var newScope = new Scope(scope);
            DeclarationBlock.CheckSemantics(newScope, errors);
            if (InstructionsBlock != null)
                InstructionsBlock.CheckSemantics(newScope, errors);

            //check the visibility of the returned type.
            ExpressionType = InstructionsBlock == null ? TypeInfo.GenerateVoidInfo() : this.InstructionsBlock.ExpressionType;
            if (ExpressionType != null && ExpressionType.Type != TypesEnumeration.Void && !scope.ContainsType(ExpressionType.Name))
                errors.Add(SemanticError.TypeNotVisible(ExpressionType.Name, this));
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
Example #5
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            var varInfo = scope.GetVarInstance(Record.Text);
            //Verify if the variable exist
            if (varInfo == null)
            {
                errors.Add(SemanticError.UndefinedVariableUsed(this.Record.Text, this));
                return;
            }

            NextNested.CheckSemantics(varInfo.VariableType, scope, errors);
            ExpressionType = NextNested.ExpressionType;
            Record.ILName = scope.GetILVarNames(Record.Text);
            ILName = scope.GetILVarNames(Record.Text);
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
Example #6
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            RecordIdentifier.ILName = scope.GetILTypeName(RecordIdentifier.Text);

            var typeInfo = scope.GetType(this.RecordIdentifier.Text);
            //check if the record type is defined
            if (typeInfo == null || typeInfo.Type != TypesEnumeration.Record || scope.GetType(typeInfo.Name).Name != scope.GetType(this.RecordIdentifier.Text).Name)
            {
                errors.Add(SemanticError.TypeNotDefined(this.RecordIdentifier.Text, this));
                return;
            }

            var recordInfo = (RecordInfo) typeInfo;
            //the count of parameters used to define and to initialice a record must match.
            if (recordInfo.FieldsCount != this.FieldInitialicer.Count)
            {
                errors.Add(SemanticError.WrongParameterNumber("Record", this.RecordIdentifier.Text, recordInfo.FieldsCount, this.FieldInitialicer.Count, this));
                return;
            }

            for (int i = 0; i < recordInfo.FieldsCount; i++)
            {
                var assignNode = this.FieldInitialicer[i];
                assignNode.CheckSemantics(scope, errors);

                //check the field name and order
                if (assignNode.Field.Text != recordInfo.Parameters[i].Identifier)
                    errors.Add(SemanticError.WrongFieldInit(this.RecordIdentifier.Text, recordInfo.Parameters[i].Identifier, this));
                //check the field type
                if (assignNode.Value.ExpressionType.Type == TypesEnumeration.Nil)
                {
                    if (!scope.GetType(recordInfo.Parameters[i].Type).Nilable)
                        errors.Add(SemanticError.InvalidNilAssignation(recordInfo.Parameters[i].Identifier, this));
                }
                else if (scope.GetType(assignNode.Value.ExpressionType.Name).Name != scope.GetType(recordInfo.Parameters[i].Type).Name)
                    errors.Add(SemanticError.WrongType(assignNode.Value.ExpressionType.Name, recordInfo.Parameters[i].Type, this));

                FieldInitialicer[i].ILName = RecordIdentifier.ILName + string.Format(".{0}", assignNode.Field.Text);
            }
            ExpressionType = recordInfo;
            ExpressionType.ILName = scope.GetILTypeName(ExpressionType.Name);
        }
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            CheckFunctionId(scope,errors);

            //check the return type is defined already
            if (!scope.ContainsType(ReturnType.Text))
            {
                errors.Add(SemanticError.TypeNotDefined(ReturnType.Text, this));
                return;
            }
            var newScope = CreateFunctionScope(scope, errors);
            Body.CheckSemantics(newScope, errors);

            if (Body.ExpressionType.Type == TypesEnumeration.Nil)
            {
                if (!scope.GetType(ReturnType.Text).Nilable)
                    errors.Add(SemanticError.InvalidNilAssignation(ReturnType.Text,this));
            }
            else if (Body.ExpressionType.Name != scope.GetType(ReturnType.Text).Name)
                errors.Add(SemanticError.WrongType(ReturnType.Text, Body.ExpressionType.Name, this));

            ReturnType.ILName = ReturnType != null ? scope.GetILTypeName(ReturnType.Text) : "voidScope0";
            Identifier.ILName = string.Format("{0}Scope{1}", Identifier, scope.CurrentScope);
        }
Example #8
0
 public override void CheckSemantics(Scope scope, List<SemanticError> errors)
 {
     CheckIdentifier(scope, errors);
     Identifier.ILName = string.Format("{0}Scope{1}", Identifier.Text, scope.CurrentScope);
     Alias.ILName = scope.GetILTypeName(Alias.Text);
 }
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            Value.CheckSemantics(scope, errors);

            if (scope.ContainsVarInstance(Identifier.Text, true) || scope.ContainsRoutine(Identifier.Text, true))
                errors.Add(SemanticError.DefinedVariable(Identifier.Text, this));
            if (Scope.standard_functions.Contains(Identifier.Text))
                errors.Add(SemanticError.HidingAnStandardFunc("Function", Identifier.Text, this));

            if (VariableType != null)
            {
                if (!scope.ContainsType(this.VariableType.Text))
                {
                    errors.Add(SemanticError.TypeNotDefined(this.VariableType.Text, this));
                    return;
                }
                //check if the value of the variable has the same type that the defined
                else if (Value.ExpressionType.Type == TypesEnumeration.Nil)
                {
                    if (!scope.GetType(VariableType.Text).Nilable)
                        errors.Add(SemanticError.InvalidNilAssignation(VariableType.Text, this));
                }
                else if (scope.GetType(this.Value.ExpressionType.Name).Name != scope.GetType(this.VariableType.Text).Name)
                    errors.Add(SemanticError.WrongType(this.VariableType.Text, this.Value.ExpressionType.Name, this));
            }
            else
            {
                switch (Value.ExpressionType.Type)
                {
                    case TypesEnumeration.Nil:
                        errors.Add(SemanticError.InvalidNilAssignation(Identifier.Text, this));
                        return;
                    case TypesEnumeration.Void:
                        errors.Add(SemanticError.NonValuedAssignation(this));
                        return;
                }
            }

            Identifier.ExpressionType = VariableType != null ? scope.GetType(VariableType.Text) : Value.ExpressionType;
            Identifier.ILName = string.Format("{0}Scope{1}", Identifier.Text, scope.CurrentScope);
            Value.ExpressionType.ILName = scope.GetILTypeName(Value.ExpressionType.Name);
        }
Example #10
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            this.Length.CheckSemantics(scope, errors);
            this.DefaultValue.CheckSemantics(scope, errors);

            //check if the array identifier is defined
            var typeInfo = scope.GetType(this.ArrayIdentifier.Text);
            if (typeInfo == null)
            {
                errors.Add(SemanticError.TypeNotDefined(this.ArrayIdentifier.Text, this));
                return;
            }
            /*if (scope.GetType(typeInfo.Name).Name != scope.GetType(ArrayIdentifier.Text).Name)
            {
                errors.Add(SemanticError.WrongType(ExpressionType.Name, typeInfo.Name, this));
                return;
            }*/
            if (typeInfo.Type != TypesEnumeration.Array)
            {
                errors.Add(SemanticError.WrongType("Array", typeInfo.Name, this));
                return;
            }

            var arrayInfo = (ArrayInfo) typeInfo;
            //check if lenght is int
            if (this.Length.ExpressionType.Type != TypesEnumeration.Integer)
                errors.Add(SemanticError.InvalidNumber("The length", this));
            //default value must be the same type of the defined
            if (DefaultValue.ExpressionType.Type == TypesEnumeration.Nil)
            {
                if (!scope.GetType(arrayInfo.ItemsType).Nilable)
                    errors.Add(SemanticError.InvalidNilAssignation(arrayInfo.ItemsType, this));
            }
            else if (arrayInfo.ItemsType != scope.GetType(DefaultValue.ExpressionType.Name).Name)
                errors.Add(SemanticError.WrongType(arrayInfo.ItemsType, this.DefaultValue.ExpressionType.Name, this));

            this.ExpressionType = scope.GetType(ArrayIdentifier.Text);
            ArrayIdentifier.ILName = string.Format("{0}Scope{1}", ArrayIdentifier, scope.CurrentScope);
            DefaultValue.ILName = scope.GetILTypeName(arrayInfo.ItemsType);
        }