Add integer parsing
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
adbe98ec00
commit
8a97def6b2
|
@ -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) {}
|
||||||
|
|
|
@ -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") {
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue