We can be pro Fortnite gamers

This commit is contained in:
ItzzCode 2022-10-22 02:00:10 -04:00
parent 0d50c28054
commit dda03107b1
2 changed files with 85 additions and 0 deletions

84
lexer.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "global.h"
// 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
assignment, // <-
tree, // tree{tree, tree{tree{tree, tree}, tree, tree{tree}}}
integer, // integer ._.
doubleTok, // double o_o
string, // string O_O
};
std::string identifierStr; // filled if string
long intVal; // filled if integer
double doubleVal; // filled if decimal
int getTok() {
int lastChar = ' ';
// skip le whitespace
while( isspace(lastChar) )
lastChar = getchar();
// letters
if( isalpha(lastChar) ) {
identifierStr = lastChar;
while( isalnum((lastChar = getchar())) )
identifierStr += lastChar;
// im not sure what this
if( identifierStr == "external" )
return external;
// varble
return variable;
}
// digits
if( isdigit(lastChar) || lastChar == '.' ) {
std::string numStr;
// get numbers
do {
numStr += lastChar;
lastChar = getchar();
} while( isdigit(lastChar) || lastChar == '.' );
// numbered
if( numStr.find('.') == std::string::npos ) {
intVal = atol(numStr.c_str());
return integer;
} else {
doubleVal = strtod(numStr.c_str(), 0);
return doubleTok;
}
}
// <-----------------------------------------------------
if( lastChar == '<' ) {
if( (lastChar = getchar()) == '-' )
return assignment;
}
// comments
if( lastChar == '#' ) {
do
lastChar = getchar();
while (lastChar != EOF && lastChar != '\n' && lastChar != '\r');
if (lastChar != EOF)
return getTok();
}
// EOF?
if (lastChar == EOF)
return getTok();
// return negative ascii value if none match
int thisChar = lastChar;
lastChar = getchar();
return -thisChar;
}

1
parser.cpp Normal file
View File

@ -0,0 +1 @@
#include "global.h"