public CodeBlockNode AddNode(IAbstractSyntaxTree lexerNode)
        {
            switch (lexerNode.Type)
            {
            case Lexer.TokenType.WhileLoop:
                return(AddNode(WhileBlock.Parse(this, lexerNode)));

            case Lexer.TokenType.ConditionalSentence:
                return(AddNode(ConditionBlockNode.Parse(this, lexerNode)));

            case Lexer.TokenType.CodeBlockNode:
                return(AddNode(CodeBlockNode.Parse(this, lexerNode)));

            case Lexer.TokenType.ForLoop:
                return(AddNode(ForLoopNode.Parse(this, lexerNode)));

            case Lexer.TokenType.ForEachLoop:
                return(AddNode(ForEachNode.Parse(this, lexerNode)));

            case Lexer.TokenType.StatementWithEndOfLine:
                if (lexerNode.Children.Count == 2)
                {
                    return(AddStatement(lexerNode.Children[0]));
                }
                else
                {
                    //empty statement a.k.a ";"
                    return(this);
                }

            case Lexer.TokenType.UnknownNode:
                ErrorCode.InvalidStructure.ReportAndThrow(Parser.GetSequencePoint(lexerNode), "Could not parse as a statement");
                return(null);   //unreachable

            default:
                ErrorCode.InvalidStructure.ReportAndThrow(Parser.GetSequencePoint(lexerNode), "Unexpected node {0} in while parsing code block", lexerNode.Type);
                return(null);   //unreachable
            }
        }
        public static ParserNode Parse(ContextNode context, IAbstractSyntaxTree lexerNode)
        {
            Contract.Requires(context != null);

            CodeBlockNode  init      = null;
            ExpressionNode condition = null;
            CodeBlockNode  increment = null;

            IAbstractSyntaxTree initNode      = lexerNode.Children[2];
            IAbstractSyntaxTree conditionNode = lexerNode.Children[4];
            IAbstractSyntaxTree incrementNode = lexerNode.Children[6];
            IAbstractSyntaxTree bodyNode      = lexerNode.Children[8];

            if (initNode.Type != TokenType.Empty)
            {
                init = CodeBlockNode.Create(context, context.Parser.GetSequencePoint(initNode));
                init.AddStatement(initNode);
                //makes init scope encompass for scope
                context = init;
            }

            if (conditionNode.Type != TokenType.Empty)
            {
                condition = ExpressionNode.Parse(context, conditionNode, context.Parser.Bool);
            }

            if (incrementNode.Type != TokenType.Empty)
            {
                increment = CodeBlockNode.Create(context, context.Parser.GetSequencePoint(incrementNode));
                increment.AddStatement(incrementNode);
            }

            var body = CodeBlockNode.Parse(context, bodyNode);

            return(ForLoopNode.Create(context, init, condition, increment, body, context.Parser.GetSequencePoint(lexerNode)));
        }