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; }
public override void EnterForStatement([NotNull] CmanParser.ForStatementContext context) { _nodes.Push(new ASTForStatementNode(context, _nodes.Peek())); }
public ASTForStatementNode(CmanParser.ForStatementContext context, ASTNode parent) : base(parent) { SetLocation(context); }