Fix number parsing and add ++ operator

This commit is contained in:
Brandon Dyck 2023-06-08 08:00:26 -06:00
parent c991893f76
commit 0d36ba4a52

View File

@ -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 :