From 68ea89ece61488909f4b1c1b392ba01a276c9770 Mon Sep 17 00:00:00 2001 From: Andrew Montenigro Date: Tue, 18 Nov 2025 09:12:59 -0600 Subject: [PATCH] base c++ work --- neopb.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 neopb.cpp diff --git a/neopb.cpp b/neopb.cpp new file mode 100644 index 0000000..152d3a1 --- /dev/null +++ b/neopb.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include + +typedef enum { + FUNCTION, + SUB, + END, + AS, + TYPE, + IDENTIFIER, + INTEGER, + STRING, + OPAREN, + CPAREN, + COMMA, + QUOTE, + EQUALS, + TOKEN_TYPE_COUNT +} PBTokenType; + +typedef struct { + PBTokenType type; + std::string value; +} PBToken; + +std::vector tokenize(std::string code); + +int main(int argc, char* argv[]) { + //for (int n = 0; n < argc; n++) { + // std::cout << "arg" << n << ": " << argv[n] << std::endl; + //} + + return 0; +} + +std::vector tokenize(std::string code) { + const PBToken tokenize_one = [](std::string fragment) { + const std::regex re_func("\bfunction\b", std::regex_constants::icase); + const std::regex re_sub( "\bsub\b", std::regex_constants::icase); + const std::regex re_end( "\bend\b", std::regex_constants::icase); + const std::regex re_as("\bas\b", std::regex_constants::icase); + const std::regex re_type("\blong\b", std::regex_constants::icase); + const std::regex re_identifier("\b[a-zA-Z]+\b"); + const std::regex re_integer("\b[0-9]+\b"); + const std::regex re_string("\".*\""); + const std::regex re_oparen("\("); + const std::regex re_cparen("\)"); + const std::regex re_comma(","); + const std::regex re_quote("'"); + const std::regex re_equals("="); + + PBTokenType tt = SUB; + std::string val = fragment.trim(); + + + + return { .type = tt, .value = val }; + }; + std::vector tokens(); + while(code.length() > 0) { + int split = code.find(' '); + std::string fragment = split > 0 ? code.substr(0, split) : code; + tokens.push_back(tokenize_one(fragment)); + } + return tokens; +}