private bool TryDeclaration(out Statement statement) { statement = default; try { if (AdvanceIfMatches(out var consumed, TokenType.Fun)) { statement = FunctionDeclaration(); } else if (AdvanceIfMatches(out consumed, TokenType.Var)) { statement = VariableDeclaration(); } else { statement = Statement(); } return(true); } catch (SynchronizeSignal s) { Synchronize(); Console.Error.WriteLine(s.Message); return(false); } }
private Statement IfStatement() { AdvanceIfMatchesOrCrashIfNotMatches(TokenType.LeftParenthesis, "Expected '(' after 'if'.", out _); var condition = Expression(); AdvanceIfMatchesOrCrashIfNotMatches(TokenType.RightParenthesis, "Expected ')' after 'if'.", out _); var thenBranch = Statement(); Statement elseBranch = default; if (AdvanceIfMatches(out _, TokenType.Oppure)) { elseBranch = Statement(); } return(new Statements.If(condition, thenBranch, elseBranch)); }