diff --git a/Parser.cs b/Parser.cs index c9f0098..d4e2022 100644 --- a/Parser.cs +++ b/Parser.cs @@ -163,6 +163,25 @@ class Parser return ifExpr(); } + private Expr control() + { + switch (peek().type) + { + case TokenType.If: + advance(); + Expr condition = expression(); + consume(TokenType.Then, "Expect 'then' after condition."); + Expr thenCase = expression(); + consume(TokenType.Else, "Expect 'else' after 'then' case."); + Expr elseCase = expression(); + return new If { Condition = condition, Then = thenCase, Else = elseCase }; + case TokenType.When: + throw new NotImplementedException(); + } + + return primary(); + } + private Expr ifExpr() { if (match(TokenType.If))