added scientific notation

This commit is contained in:
minirop
2015-08-16 11:50:45 +02:00
parent 9b18d38546
commit 0c539af6ac
9 changed files with 32 additions and 3 deletions
+16 -1
View File
@@ -608,7 +608,6 @@ static void readHexNumber(Parser* parser)
// Finishes lexing a number literal.
static void readNumber(Parser* parser)
{
// TODO: scientific, etc.
while (isDigit(peekChar(parser))) nextChar(parser);
// See if it has a floating point. Make sure there is a digit after the "."
@@ -618,6 +617,22 @@ static void readNumber(Parser* parser)
nextChar(parser);
while (isDigit(peekChar(parser))) nextChar(parser);
}
// See if the number is in scientific notation
if (peekChar(parser) == 'e' || peekChar(parser) == 'E')
{
nextChar(parser);
// if the exponant is negative
if(peekChar(parser) == '-') nextChar(parser);
if(!isDigit(peekChar(parser)))
{
lexError(parser, "Unterminated scientific notation.");
}
while (isDigit(peekChar(parser))) nextChar(parser);
}
makeNumber(parser, false);
}