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; using NamedIdentifier::NamedIdentifier;
}; };
namespace types { namespace types {
struct Integer: ParseComponent {
long double value;
Integer(const string& value): value(stold(value)) {}
};
struct String: ParseComponent { struct String: ParseComponent {
const string content; const string content;
explicit String(const char* string): content(string) {} 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); const tok& current = lexed[i], next = hasNext ? lexed[i + 1] : tok(UNEXPECTED, current.line);
switch (current.toktype) { 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 STRING: parseTree << types::String(current.toktext.data()); break;
case IDENTIFIER: { case IDENTIFIER: {
if (current.toktext == "class" || current.toktext == "structure") { 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) << '('; output << ((parseComponent.name == "print") ? print_functions.first : (parseComponent.name == "print_line") ? print_functions.second : parseComponent.name) << '(';
separate_transpileTree(parseComponent, ", "); separate_transpileTree(parseComponent, ", ");
output << ')'; output << ')';
) ),
make_task(StandardComponents::types::Integer, output << parseComponent.value;)
})); }));
return staticMap; return staticMap;
}; };