Example #1
0
        public override void Visit(ForLoopNode node)
        {
            AllType?varDclNodeType;

            _symbolTable.SetCurrentNode(node);
            _symbolTable.OpenScope(BlockType.ForLoop);
            VisitChildren(node);

            if (node.Increment != null && (node.VariableDeclaration != null || node.FromValueNode != null) && node.ToValueOperation != null)
            {
                node.Increment.Accept(this);
                if (node.VariableDeclaration != null)
                {
                    node.VariableDeclaration.Accept(this);
                }
                if (node.FromValueNode != null)
                {
                    node.FromValueNode.Accept(this);
                }
                node.ToValueOperation.Accept(this);
            }

            if (node.Increment is ExpressionNode incrementNode)
            {
                if (node.VariableDeclaration is VariableDclNode varDclNode)
                {
                    varDclNodeType = _symbolTable.RetrieveSymbol(varDclNode.Name);
                    if (varDclNodeType != AllType.INT || incrementNode.OverAllType != AllType.INT)
                    {
                        _symbolTable.WrongTypeConditionError();
                    }
                }
                else
                {
                    if (node.FromValueNode is ExpressionNode expNode)
                    {
                        if (expNode.OverAllType != AllType.INT || incrementNode.OverAllType != AllType.INT)
                        {
                            _symbolTable.WrongTypeConditionError();
                        }
                    }
                    else
                    {
                        if (node.FromValueNode.Type_enum != AllType.INT || incrementNode.OverAllType != AllType.INT)
                        {
                            _symbolTable.WrongTypeConditionError();
                        }
                    }
                }
            }
            _symbolTable.CloseScope();
        }
Example #2
0
        public override AbstractNode VisitForLoop([NotNull] GiraphParser.ForLoopContext context)
        {
            ForLoopNode        ForLoop        = new ForLoopNode(context.Start.Line, context.Start.Column);
            var                contextInside  = context.forCondition().forConditionInside();
            BoolComparisonNode boolComparison = new BoolComparisonNode(context.Start.Line, context.Start.Column);

            boolComparison.ComparisonOperator = "<";
            if (contextInside.forConditionStart().forConditionDcl() != null)
            {
                ForLoop.VariableDeclaration = Visit(contextInside.forConditionStart().forConditionDcl());
                VariableNode varNode = new VariableNode(context.Start.Line, context.Start.Column);
                varNode.Name             = (ForLoop.VariableDeclaration as VariableDclNode).Name;
                varNode.Type             = (ForLoop.VariableDeclaration as VariableDclNode).Type;
                boolComparison.Left      = varNode;
                ForLoop.ToValueOperation = boolComparison;
            }
            else if (contextInside.forConditionStart().expression() != null)
            {
                ForLoop.FromValueNode    = Visit(contextInside.forConditionStart().expression());
                ForLoop.ToValueOperation = Visit(contextInside.expression(0));
            }

            boolComparison.Right = Visit(contextInside.expression(0));
            if (contextInside.expression(1) != null)
            {
                ForLoop.Increment = Visit(contextInside.expression(1));
            }
            else
            {
                ExpressionNode expNode = new ExpressionNode(context.Start.Line, context.Start.Column);
                ConstantNode   conNode = new ConstantNode(context.Start.Line, context.Start.Column);
                conNode.Type  = "int";
                conNode.Value = "1";
                expNode.ExpressionParts.Add(conNode);

                ForLoop.Increment = expNode;
                //ForLoop.Increment
            }

            // Visit all the children of the Codeblock associated with the ForLoop
            foreach (var Child in context.codeBlock().codeBlockContent())
            {
                // Adopt the children
                ForLoop.AdoptChildren(Visit(Child.GetChild(0)));
            }
            return(ForLoop);
        }
 public override void Visit(ForLoopNode node)
 {
 }
Example #4
0
 public abstract void Visit(ForLoopNode node);