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 <tuple>
#include <string>
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;
getTok();
}

View File

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