Add integer parsing

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-03-22 13:40:17 +01:00
parent adbe98ec00
commit 8a97def6b2
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 16 additions and 1 deletions

View File

@ -105,6 +105,10 @@ namespace StandardComponents {
using NamedIdentifier::NamedIdentifier;
};
namespace types {
struct Integer: ParseComponent {
long double value;
Integer(const string& value): value(stold(value)) {}
};
struct String: ParseComponent {
const string content;
explicit String(const char* string): content(string) {}

View File

@ -42,6 +42,16 @@ namespace Parser {
const tok& current = lexed[i], next = hasNext ? lexed[i + 1] : tok(UNEXPECTED, current.line);
switch (current.toktype) {
case NUMBER: {
types::Integer Int = current.toktext;
if (nextAre({DOT, NUMBER})) {
i += 2;
const string& right = lexed[i].toktext;
Int.value += stold(right) / pow(10, right.size());
}
parseTree << Int;
break;
}
case STRING: parseTree << types::String(current.toktext.data()); break;
case IDENTIFIER: {
if (current.toktext == "class" || current.toktext == "structure") {

View File

@ -132,7 +132,8 @@ public:
output << ((parseComponent.name == "print") ? print_functions.first : (parseComponent.name == "print_line") ? print_functions.second : parseComponent.name) << '(';
separate_transpileTree(parseComponent, ", ");
output << ')';
)
),
make_task(StandardComponents::types::Integer, output << parseComponent.value;)
}));
return staticMap;
};