Esempio n. 1
0
        private AstItem ReadIfStatement(TokenIterator tokens)
        {
            tokens.PopExpected(TokenKind.If);
            var expression = ReadExpression(tokens, TokenKind.CurlyBracketOpen);

            tokens.PopExpected(TokenKind.CurlyBracketOpen);
            var statements = ReadStatements(tokens);

            tokens.PopExpected(TokenKind.CurlyBracketClose);

            List <AstItem> elseStatements = null;

            var current = tokens.Current();

            if (current.Kind == TokenKind.Else)
            {
                tokens.PopExpected(TokenKind.Else);
                tokens.PopExpected(TokenKind.CurlyBracketOpen);
                elseStatements = ReadStatements(tokens);
                tokens.PopExpected(TokenKind.CurlyBracketClose);
            }

            return(AstItem.IfStatement(expression, statements, elseStatements));
        }