コード例 #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 VisitSimpleExpression(SimpleExpression node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            node.Term.Accept(this);
            TokenType termEval = node.Term.EvaluationType;

            if (node.Tail != null)
            {
                node.Tail.Accept(this);
                TokenType tailEval = node.Tail.EvaluationType;

                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.Tail.Operation, termEval, tailEval))
                {
                    termEval = TokenType.ERROR;
                }
            }

            if (node.AdditiveInverse && !LegitOperationChecker.IsLegitOperationForEvaluations(TokenType.UNARY_OP_NEGATIVE, termEval))
            {
                termEval = TokenType.ERROR;
            }

            node.EvaluationType = termEval;
        }
コード例 #3
0
        public void VisitTermNode(TermNode node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            node.Factor.Accept(this);
            TokenType factorEval = node.Factor.EvaluationType;

            if (node.TermTail != null)
            {
                node.TermTail.Accept(this);
                TokenType tailEval = node.TermTail.EvaluationType;

                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.TermTail.Operation, factorEval, tailEval))
                {
                    factorEval = TokenType.ERROR;
                }

                // MUST HANDLE CASES WHERE INT + REAL EVALUATED
            }

            node.EvaluationType = factorEval;
        }
コード例 #4
0
        /// <summary>
        /// Checks the static semantic constraints of an AssignNode.
        /// </summary>
        /// <returns>An void.</returns>
        /// <param name="node">Node.</param>
        public void VisitAssignNode(AssignNode node)
        {
            node.IDNode.Accept(this);
            node.AssignValueExpression.Accept(this);
            bool errored = false;

            TokenType varEval  = node.IDNode.EvaluationType;
            TokenType exprEval = node.AssignValueExpression.EvaluationType;

            bool     assignable  = node.IDNode.EvaluationType != TokenType.ERROR;
            Property varProperty = node.Scope.GetProperty(node.IDNode.IDNode.ID);

            if (varProperty.DeclarationRow > node.Token.Row)
            {
                analyzer.notifyError(new UndeclaredVariableError(node.IDNode));
                assignable = false;
                errored    = true;
            }

            if (!LegitOperationChecker.isAssignCompatible(varEval, exprEval) && !errored)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
                assignable = false;
                errored    = true;
            }

            if (!LegitOperationChecker.CanBeAssignedTo(varEval, exprEval) && !errored)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
                assignable = false;
                errored    = true;
            }

            if (assignable)
            {
                varProperty.Assigned = true;
            }
        }
コード例 #5
0
        public void VisitExpressionNode(ExpressionNode node)
        {
            node.Accept(this.typeChecker);
            node.SimpleExpression.Accept(this);

            if (node.ExpressionTail != null)
            {
                node.ExpressionTail.Accept(this);
                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.ExpressionTail.Operation, node.SimpleExpression.EvaluationType, node.ExpressionTail.RightHandSide.EvaluationType))
                {
                    node.EvaluationType = TokenType.ERROR;
                }
                else
                {
                    node.EvaluationType = TokenType.BOOLEAN_VAL;
                }
            }

            if (node.EvaluationType == TokenType.ERROR)
            {
                analyzer.notifyError(new IllegalTypeError(node));
            }
        }
コード例 #6
0
        public void VisitSimpleExpressionTail(SimpleExpressionTail node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            node.Term.Accept(this);
            TokenType termEval = node.Term.EvaluationType;

            if (node.Tail != null)
            {
                node.Tail.Accept(this);
                TokenType tailEval = node.Tail.EvaluationType;

                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.Tail.Operation, termEval, tailEval))
                {
                    termEval = TokenType.ERROR;
                }
            }

            node.EvaluationType = termEval;
        }
コード例 #7
0
        public void VisitTermTailNode(TermTail node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            node.Factor.Accept(this);
            TokenType factorEval = node.Factor.EvaluationType;

            if (node.ChildTermTail != null)
            {
                node.ChildTermTail.Accept(this);
                TokenType tailEval = node.ChildTermTail.EvaluationType;

                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.ChildTermTail.Operation, factorEval, tailEval))
                {
                    factorEval = TokenType.ERROR;
                }
            }

            node.EvaluationType = factorEval;
        }
コード例 #8
0
        public void VisitExpressionNode(ExpressionNode node)
        {
            if (node.HasAlreadyBeenEvaluated)
            {
                return;
            }

            node.SimpleExpression.Accept(this);
            TokenType expressionEvaluation = node.SimpleExpression.EvaluationType;

            if (node.ExpressionTail != null)
            {
                node.ExpressionTail.Accept(this);
                TokenType tailEvaluation = node.ExpressionTail.RightHandSide.EvaluationType;

                if (!LegitOperationChecker.IsLegitOperationForEvaluations(node.ExpressionTail.Operation, expressionEvaluation, tailEvaluation))
                {
                    expressionEvaluation = TokenType.ERROR;
                }
            }

            node.EvaluationType = expressionEvaluation;
        }