示例#1
0
        public void VisitArrayAssignNode(ArrayAssignStatement node)
        {
            node.IndexExpression.Accept(this);
            node.AssignValueExpression.Accept(this);
            node.IDNode.Accept(this);

            TokenType exprEval = node.AssignValueExpression.EvaluationType;

            Property prop = node.IDNode.Scope.GetProperty(node.IDNode.IDNode.ID);

            if (node.IDNode.Scope.GetProperty(node.IDNode.IDNode.ID).GetTokenType() != TokenType.TYPE_ARRAY)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
            }
            else
            {
                ArrayProperty arrProp = (ArrayProperty)prop;

                if (prop.DeclarationRow > node.Token.Row)
                {
                    analyzer.notifyError(new UndeclaredVariableError(node.IDNode));
                }

                if (!LegitOperationChecker.isAssignCompatible(arrProp.ArrayElementType, exprEval))
                {
                    analyzer.notifyError(new IllegalTypeError(node));
                }

                if (!LegitOperationChecker.CanBeAssignedTo(arrProp.ArrayElementType, exprEval))
                {
                    analyzer.notifyError(new IllegalAssignmentError(node));
                }
            }
        }
示例#2
0
        public void VisitArrayAccessNode(ArrayAccessNode node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            Property prop = node.Scope.GetProperty(node.ArrayIdNode.ID);

            if (prop.GetTokenType() != TokenType.TYPE_ARRAY)
            {
                node.EvaluationType = TokenType.ERROR;
            }
            else
            {
                ArrayProperty arrayProp = (ArrayProperty)prop;
                node.EvaluationType = arrayProp.ArrayElementType;
            }
        }