From 0d36ba4a52c7b34a6502b3e5a202be94dda818f5 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Thu, 8 Jun 2023 08:00:26 -0600 Subject: [PATCH] Fix number parsing and add ++ operator --- Program.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 5e41e2d..5c65f8a 100644 --- a/Program.cs +++ b/Program.cs @@ -83,6 +83,7 @@ enum TokenType Period, Equal, Plus, Minus, Asterisk, Slash, + PlusPlus, DoubleEqual, Bang, BangEqual, LessEqual, GreaterEqual, @@ -238,8 +239,11 @@ class Scanner // Look for a fractional part. if (peek() == '.' && isDigitOrSeparator(peekNext() ?? '\0')) { + match('.'); while (match(isDigitOrSeparator)) ; } + double value = Double.Parse(source.Substring(start, current - start)); + addToken(TokenType.Number, value); } private bool isIdentifierStartChar(char c) @@ -277,7 +281,6 @@ class Scanner case '`': addToken(TokenType.Backtick); break; case ',': addToken(TokenType.Comma); break; case '.': addToken(TokenType.Period); break; - case '+': addToken(TokenType.Plus); break; case '*': addToken(TokenType.Asterisk); break; case '/': addToken(TokenType.Slash); break; case '-': @@ -286,6 +289,9 @@ class Scanner case '!': addToken(match('=') ? TokenType.BangEqual : TokenType.Bang); break; + case '+': + addToken(match('+') ? TokenType.PlusPlus : TokenType.Plus); + break; case '=': addToken(match('=') ? TokenType.DoubleEqual : match('>') ? TokenType.DoubleArrow :