I really love to Chug Jug with you
This commit is contained in:
parent
8d1504a6a7
commit
0d50c28054
56
compiler.cpp
56
compiler.cpp
@ -4,59 +4,9 @@
|
||||
|
||||
// derived from https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl01.html
|
||||
|
||||
// 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
|
||||
tree, // tree{tree, tree{tree{tree, tree}, tree, tree{tree}}}
|
||||
integer, // integer ._.
|
||||
string, // string O_O
|
||||
};
|
||||
|
||||
std::string identifierStr; // filled if string
|
||||
long numVal; // filled if integer
|
||||
|
||||
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 == "external" )
|
||||
return external;
|
||||
|
||||
if( isdigit(lastChar) ) {
|
||||
std::string numStr;
|
||||
do {
|
||||
numStr += lastChar;
|
||||
lastChar = getchar();
|
||||
} while( isdigit(lastChar) );
|
||||
|
||||
numVal = atol(numStr.c_str());
|
||||
return integer;
|
||||
}
|
||||
|
||||
if( lastChar == '#' ) {
|
||||
do
|
||||
lastChar = getchar();
|
||||
while (lastChar != EOF && lastChar != '\n' && lastChar != '\r');
|
||||
|
||||
if (lastChar != EOF)
|
||||
return getTok();
|
||||
}
|
||||
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
#include "lexer.cpp"
|
||||
#include "parser.cpp"
|
||||
|
||||
void compiler( char filename[] ) {
|
||||
getTok();
|
||||
|
||||
while(true) LOG(getTok())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user