Ejemplo n.º 1
0
        public override void CheckSemantics(Scope scope, List<SemanticError> errors)
        {
            //check the existence and the semantic of the left value.
            Identifier.CheckSemantics(scope, errors);
            //check the semantick of the expression.
            this.Expr.CheckSemantics(scope, errors);
            if (Identifier is IdNode)
                if (scope.ContainsVarInstance(Identifier.Text) && scope.GetVarInstance(Identifier.Text).ReadOnly)
                    errors.Add(SemanticError.ReadOnlyAssing(Identifier.Text,this));

            if (Expr.ExpressionType.Type == TypesEnumeration.Nil)
            {
                if (!scope.GetType(Identifier.ExpressionType.Name).Nilable)
                    errors.Add(SemanticError.InvalidNilAssignation(Identifier.ExpressionType.Name, this));
            }
            else if (Expr.ExpressionType.Type == TypesEnumeration.Void || scope.GetType(Identifier.ExpressionType.Name).Name != scope.GetType(Expr.ExpressionType.Name).Name)
                errors.Add(SemanticError.WrongType(Identifier.ExpressionType.Name, Expr.ExpressionType.Name, this));
        }
Ejemplo n.º 2
0
        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);
        }