private void ParseIfStatement() { var token = GetNext(); if (token.Type == TokenType.If) { if (token.Partner != null) { ParseIfElse(); return; } } else { throw new Exception("Expected If identifier"); } Match(TokenType.OpenParenthesis); object condition = ParseExpression(); Match(TokenType.CloseParenthesis); _compileCommands.AddLast(new[] { "Do Nothing" }); var insertIfBefore = _compileCommands.Tail; bool hasBrackets = false; if (PeekNext().Type == TokenType.OpenCurlyBracket) { GetNext(); hasBrackets = true; } do { ParseStatement(); } while (hasBrackets && PeekNext().Type != TokenType.CloseCurlyBracket); if (hasBrackets) { Match(TokenType.CloseCurlyBracket); } _compileCommands.AddLast(new[] { "Do Nothing" }); _compileCommands.AddBefore(insertIfBefore, new[] { "$if", condition, new object[] { "$goto", _compileCommands.Tail } }); }