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 { // any non tokens get to be returned as ascii val from 0 to -255
comment, enum token {
variable, eof, // End of File
integer, external, // C stuff
string, variable, // Name of a variable
construct integer, // integer ._.
string, // string O_O
}; };
type tokenType; std::string identifierStr; // filled if string
char* tokenValue; long NumVal; // filled if integer
tokens( type aTokenType, char* aTokenValue ) { int getTok() {
tokenType = aTokenType; int lastChar = ' ';
tokenValue = aTokenValue;
// 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;
} }
};
tokens getTok( char code[] ) {
if( code[0] == '#' )
return tokens(tokens::comment, "");
return tokens(tokens::comment, "");
} }
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;