Пример #1
0
        public void VisitWhileLoopNode(WhileNode node)
        {
            ExpressionNode condition = node.Condition;
            StatementNode  statement = node.Statement;

            condition.Accept(this);
            statement.Accept(this);

            if (condition.EvaluationType != TokenType.BOOLEAN_VAL)
            {
                analyzer.notifyError(new IllegalTypeError(condition));
            }
        }
Пример #2
0
        public void VisitTypeNode(TypeNode node)
        {
            ExpressionNode sizeExpr = node.ArraySizeExpression;

            if (sizeExpr != null)
            {
                sizeExpr.Accept(this);

                if (sizeExpr.EvaluationType != TokenType.INTEGER_VAL)
                {
                    analyzer.notifyError(new IllegalTypeError(sizeExpr));
                }
            }
        }
Пример #3
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));
            }
        }
Пример #4
0
        public void VisitIfNode(IfNode node)
        {
            ExpressionNode condition  = node.Condition;
            StatementNode  ifBranch   = node.IfBranch;
            StatementNode  elseBranch = node.ElseBranch;

            condition.Accept(this);
            ifBranch.Accept(this);

            if (condition.EvaluationType != TokenType.BOOLEAN_VAL)
            {
                analyzer.notifyError(new IllegalTypeError(condition));
            }

            if (elseBranch != null)
            {
                elseBranch.Accept(this);

                if (ifBranch.Returns && elseBranch.Returns)
                {
                    node.Returns = true;
                }
            }
        }