diff --git a/headers/helperFunctions/HelperFunctions.h b/headers/helperFunctions/HelperFunctions.h index 92fb5cb..70feb45 100644 --- a/headers/helperFunctions/HelperFunctions.h +++ b/headers/helperFunctions/HelperFunctions.h @@ -4,7 +4,7 @@ #include #include -std::vector splitString(const std::string& input, std::string delimiter) { +inline std::vector splitString(const std::string& input, std::string delimiter) { std::vector tokens; std::string token; size_t start = 0; @@ -24,7 +24,7 @@ std::vector splitString(const std::string& input, std::string delim return tokens; } -std::string trim(const std::string& str) { +inline std::string trim(const std::string& str) { // Find the first non-whitespace character size_t start = str.find_first_not_of(" \t\n\r"); @@ -40,7 +40,7 @@ std::string trim(const std::string& str) { return str.substr(start, end - start + 1); } -std::string replaceSubstring(const std::string& str, const std::string& findSubstring, const std::string& replacement) { +inline std::string replaceSubstring(const std::string& str, const std::string& findSubstring, const std::string& replacement) { std::string result = str; size_t startPos = result.find(findSubstring); @@ -52,11 +52,11 @@ std::string replaceSubstring(const std::string& str, const std::string& findSubs return result; } -bool isHexDigit(char c) { +inline bool isHexDigit(char c) { return (std::isdigit(c) || (std::isxdigit(c) && std::islower(c))); } -u_long binaryStringToLong(const std::string& binaryString) { +inline u_long binaryStringToLong(const std::string& binaryString) { std::string binaryDigits = binaryString.substr(2); // Remove the '0b' prefix u_long result = 0; for (char ch : binaryDigits) { diff --git a/source/Lexer.cpp b/source/Lexer.cpp index 6e36bfb..50ed1f5 100644 --- a/source/Lexer.cpp +++ b/source/Lexer.cpp @@ -1,5 +1,7 @@ #include "../headers/Lexer.h" +#include "../headers/helperFunctions/HelperFunctions.h" #include +#include using namespace std; @@ -202,7 +204,7 @@ std::vector Lexer::Tokenize(std::string source){ } else { - if(!src.empty() && ishexnumber(src[0])) + if(!src.empty() && (src[0])) { if(notationChar == 'b') { while (!src.empty() && (src[0] == '0' || src[0] == '1')) { @@ -212,7 +214,7 @@ std::vector Lexer::Tokenize(std::string source){ } else if(notationChar == 'x') { - while (!src.empty() && ishexnumber(src[0])) { + while (!src.empty() && std::isxdigit(src[0])) { num += src[0]; advance(); diff --git a/source/main.cpp b/source/main.cpp index 902b4af..0778e7f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -4,51 +4,12 @@ #include "../headers/bob.h" -#include "../headers/Expression.h" -#include "../headers/Lexer.h" -#include "../headers/ASTPrinter.h" -#include "../headers/TypeWrapper.h" + int main(){ Bob bobLang; //bobLang.runFile("source.bob"); bobLang.runPrompt(); - //ASTPrinter printer; -// -// std::shared_ptr>> expression = std::make_shared> >( -// std::make_shared>>( -// Token{MINUS, "-", 1}, -// std::make_shared>>("123", true) -// ), -// Token{MINUS, "-", 1}, -// std::make_shared>>( -// std::make_shared>>("45.67", true) -// ) -// ); -// -//// Expr* e = new BinaryExpr( -//// new UnaryExpr(Token{MINUS, "-", 0}, new LiteralExpr("123")), -//// Token{STAR, "*", 0}, -//// new UnaryExpr(Token{PLUS, "+", 0}, new LiteralExpr("535")) -//// ); -// -// -// std::cout << std::dynamic_pointer_cast(printer.print(expression.get()))->value; -// -// std::cout << std::endl; - - //bobLang.runPrompt(); - -// std::shared_ptr object = std::make_shared(String{"Hi"}); -// -// if(auto num = std::dynamic_pointer_cast(object)) -// { -// std::cout << num->value << std::endl; -// }else if(auto str = std::dynamic_pointer_cast(object)) -// { -// std::cout << str->value << std::endl; -// } - return 0; }