// Build a while loop statement (a for loop with just the conditional)
        public static void BuildWhileLoop(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var whileLoop = new WhileLoop(parentExpression, currentNode.Token.Convert());
            parentExpression.ChildExpressions.Add(whileLoop);

            // Build the conditional expressoin
            parser.ConsumeParseTree(root, whileLoop.Condition, currentNode.ChildNodes[1]);

            // Build the statements that make up the body of the while loop
            parser.ConsumeParseTree(root, whileLoop, currentNode.ChildNodes[2]);
        }
Exemple #2
0
        // Emit a codedome expression representing a while loop.
        public static CodeStatement Emit(WhileLoop loop)
        {
            // A while loop is a for loop with no initializer or incrementor, only a condition.
            var i = new CodeIterationStatement(new CodeSnippetStatement(""),
                CodeDomEmitter.EmitCodeExpression(loop.Condition.ChildExpressions[0]),
                new CodeSnippetStatement(""));

            // Emit the statements found in the body of the while loop.
            foreach (var e in loop.ChildExpressions)
                i.Statements.Add(CodeDomEmitter.EmitCodeStatement(e));

            return i;
        }