float literals

This commit is contained in:
nub31
2025-05-16 20:27:42 +02:00
parent e0bbb7478e
commit 2a4401bab6
3 changed files with 121 additions and 37 deletions

View File

@@ -94,16 +94,41 @@ public class Lexer
if (char.IsDigit(current.Value))
{
var isFloat = false;
var buffer = string.Empty;
while (current.HasValue && char.IsDigit(current.Value))
while (current.HasValue)
{
buffer += current.Value;
Next();
if (current.Value == '.')
{
if (isFloat)
{
throw new Exception("More than one period found in float literal");
}
isFloat = true;
buffer += current.Value;
Next();
current = Peek();
}
else if (char.IsDigit(current.Value))
{
buffer += current.Value;
Next();
current = Peek();
}
else if (current.Value == 'f')
{
isFloat = true;
Next();
break;
}
else
{
break;
}
}
return new LiteralToken(NubPrimitiveType.I64, buffer);
return new LiteralToken(isFloat ? NubPrimitiveType.F64 : NubPrimitiveType.I64, buffer);
}
// TODO: Revisit this