From 2f69d187f282dddecb0762c1c97f4c2257611f39 Mon Sep 17 00:00:00 2001 From: ItzzCode <51547168+ItzzCode@users.noreply.github.com> Date: Thu, 20 Oct 2022 22:08:29 -0400 Subject: [PATCH] AAAAAAAAAAAAAAAAUUUUUUUUUUGGGGGGGGGGGGGGHHHHHHHHHHHHH --- compiler.cpp | 54 ++++++++++++++++++++++++++++++---------------------- main.cpp | 2 +- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/compiler.cpp b/compiler.cpp index 2ac280b..fdac1cf 100644 --- a/compiler.cpp +++ b/compiler.cpp @@ -1,33 +1,41 @@ #include "global.h" -#include +#include -class tokens { - public: - enum type { - comment, - variable, - integer, - string, - construct - }; +// derived from https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl01.html - type tokenType; - char* tokenValue; - - tokens( type aTokenType, char* aTokenValue ) { - tokenType = aTokenType; - tokenValue = aTokenValue; - } +// any non tokens get to be returned as ascii val from 0 to -255 +enum token { + eof, // End of File + external, // C stuff + variable, // Name of a variable + integer, // integer ._. + string, // string O_O }; +std::string identifierStr; // filled if string +long NumVal; // filled if integer -tokens getTok( char code[] ) { - if( code[0] == '#' ) - return tokens(tokens::comment, ""); - return tokens(tokens::comment, ""); +int getTok() { + int lastChar = ' '; + + // skip le whitespace + while( isspace(lastChar) ) + lastChar = getchar(); + + if( isalpha(lastChar) ) { // identifier: [a-zA-Z][a-zA-Z0-9]* + identifierStr = lastChar; + while( isalnum((lastChar = getchar())) ) + identifierStr += lastChar; + + if( identifierStr == "" ) + return external; + + return variable; + } } void compiler( char filename[] ) { - std::cout << getTok(filename).tokenType << ' ' << getTok(filename).tokenValue; -} \ No newline at end of file + getTok(); + +} diff --git a/main.cpp b/main.cpp index 407c39e..88f036d 100644 --- a/main.cpp +++ b/main.cpp @@ -14,7 +14,7 @@ int main( int argc, char *argv[] ) { help(); } else { LOG(argv[1]) - compiler("# a aa "); + compiler(argv[1]); } return 0;