Ejemplo n.º 1
0
        public override void ExitForStatement([NotNull] CmanParser.ForStatementContext context)
        {
            ASTBodyStatementNode body = null;
            IASTExprNode         step = null;
            IASTExprNode         cond = null;
            ASTNode         counter   = null;
            Queue <ASTNode> childs    = new Queue <ASTNode>();

            while (!(_nodes.Peek() is ASTForStatementNode))
            {
                childs.Enqueue(_nodes.Pop());
                //childs.Push(_nodes.Pop());
            }

            //has body
            if (childs.Peek() is ASTBodyStatementNode)
            {
                body = (ASTBodyStatementNode)childs.Dequeue();
            }
            int childCount = childs.Count();

            //counter, condition, step
            if (childCount == 3)
            {
                step = (IASTExprNode)childs.Dequeue();
            }
            cond    = (IASTExprNode)childs.Dequeue();
            counter = childs.Dequeue();

            ASTForStatementNode forNode = (ASTForStatementNode)_nodes.Peek();

            forNode.Counter   = counter;
            forNode.Condition = cond;
            forNode.Step      = step;
            forNode.Body      = body;
        }
Ejemplo n.º 2
0
 public override void EnterForStatement([NotNull] CmanParser.ForStatementContext context)
 {
     _nodes.Push(new ASTForStatementNode(context, _nodes.Peek()));
 }
Ejemplo n.º 3
0
 public ASTForStatementNode(CmanParser.ForStatementContext context, ASTNode parent)
     : base(parent)
 {
     SetLocation(context);
 }