AAAAAAAAAAAAAAAAUUUUUUUUUUGGGGGGGGGGGGGGHHHHHHHHHHHHH

This commit is contained in:
ItzzCode 2022-10-20 22:08:29 -04:00
parent cbc97864c9
commit 2f69d187f2
2 changed files with 32 additions and 24 deletions

View File

@ -1,33 +1,41 @@
#include "global.h" #include "global.h"
#include <tuple> #include <string>
class tokens { // derived from https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl01.html
public:
enum type {
comment,
variable,
integer,
string,
construct
};
type tokenType; // any non tokens get to be returned as ascii val from 0 to -255
char* tokenValue; enum token {
eof, // End of File
tokens( type aTokenType, char* aTokenValue ) { external, // C stuff
tokenType = aTokenType; variable, // Name of a variable
tokenValue = aTokenValue; integer, // integer ._.
} string, // string O_O
}; };
std::string identifierStr; // filled if string
long NumVal; // filled if integer
tokens getTok( char code[] ) { int getTok() {
if( code[0] == '#' ) int lastChar = ' ';
return tokens(tokens::comment, "");
return tokens(tokens::comment, ""); // 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[] ) { void compiler( char filename[] ) {
std::cout << getTok(filename).tokenType << ' ' << getTok(filename).tokenValue; getTok();
}
}

View File

@ -14,7 +14,7 @@ int main( int argc, char *argv[] ) {
help(); help();
} else { } else {
LOG(argv[1]) LOG(argv[1])
compiler("# a aa "); compiler(argv[1]);
} }
return 0; return 0;