|
|
@ -18,6 +18,8 @@ namespace dumb { |
|
|
|
"OPERATOR_COLON", |
|
|
|
"OPERATOR_COLON", |
|
|
|
"OPERATOR_ARROW", |
|
|
|
"OPERATOR_ARROW", |
|
|
|
"OPERATOR_DOUBLE_COLON", |
|
|
|
"OPERATOR_DOUBLE_COLON", |
|
|
|
|
|
|
|
"OPERATOR_AMPERSAND", |
|
|
|
|
|
|
|
"OPERATOR_PIPE", |
|
|
|
"INTEGER_LITERAL", |
|
|
|
"INTEGER_LITERAL", |
|
|
|
"FLOAT_LITERAL", |
|
|
|
"FLOAT_LITERAL", |
|
|
|
"STRING_LITERAL", |
|
|
|
"STRING_LITERAL", |
|
|
@ -63,7 +65,9 @@ namespace dumb { |
|
|
|
{"*", Token::Type::OPERATOR_ASTERISK}, |
|
|
|
{"*", Token::Type::OPERATOR_ASTERISK}, |
|
|
|
{"=", Token::Type::OPERATOR_EQUALS}, |
|
|
|
{"=", Token::Type::OPERATOR_EQUALS}, |
|
|
|
{":", Token::Type::OPERATOR_COLON}, |
|
|
|
{":", Token::Type::OPERATOR_COLON}, |
|
|
|
{".", Token::Type::OPERATOR_DOT} |
|
|
|
{".", Token::Type::OPERATOR_DOT}, |
|
|
|
|
|
|
|
{"&", Token::Type::OPERATOR_AMPERSAND}, |
|
|
|
|
|
|
|
{"|", Token::Type::OPERATOR_PIPE} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
dumb::Lexer::Lexer(Compiler& compiler, std::filesystem::path sourceFile) : compiler(compiler), line(1), column(1), pointer(0) { |
|
|
|
dumb::Lexer::Lexer(Compiler& compiler, std::filesystem::path sourceFile) : compiler(compiler), line(1), column(1), pointer(0) { |
|
|
@ -252,21 +256,25 @@ namespace dumb { |
|
|
|
size_t value; |
|
|
|
size_t value; |
|
|
|
|
|
|
|
|
|
|
|
switch (kind) { |
|
|
|
switch (kind) { |
|
|
|
case 'x': |
|
|
|
case 'x': { |
|
|
|
while (std::isdigit(this->current()) || (this->current() >= 'A' && this->current() <= 'F') || (this->current() >= 'a' && this->current() <= 'f')) |
|
|
|
while (std::isdigit(this->current()) || (this->current() >= 'A' && this->current() <= 'F') || (this->current() >= 'a' && this->current() <= 'f')) |
|
|
|
this->buffer << this->consume(); |
|
|
|
this->buffer << this->consume(); |
|
|
|
value = std::stoi(this->buffer.str(), nullptr, 16); |
|
|
|
std::string stringValue(this->buffer.str()); |
|
|
|
|
|
|
|
value = stringValue.length() > 0 ? std::stoi(stringValue, nullptr, 16) : 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'b': |
|
|
|
} |
|
|
|
|
|
|
|
case 'b': { |
|
|
|
while (this->current() == '0' || this->current() == '1') |
|
|
|
while (this->current() == '0' || this->current() == '1') |
|
|
|
this->buffer << this->consume(); |
|
|
|
this->buffer << this->consume(); |
|
|
|
value = std::stoi(this->buffer.str(), nullptr, 2); |
|
|
|
std::string stringValue(this->buffer.str()); |
|
|
|
|
|
|
|
value = stringValue.length() > 0 ? std::stoi(stringValue, nullptr, 2) : 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
std::cout << "Unexpected token '" << this->current() << "' on line " << this->line << " column " << this->column << std::endl; |
|
|
|
std::cout << "Unexpected token '" << this->current() << "' on line " << this->line << " column " << this->column << std::endl; |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
if (std::isdigit(this->current())) { |
|
|
|
if (std::isalnum(this->current())) { |
|
|
|
std::cout << "Unexpected token '" << this->current() << "' on line " << this->line << " column " << this->column << std::endl; |
|
|
|
std::cout << "Unexpected token '" << this->current() << "' on line " << this->line << " column " << this->column << std::endl; |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|