42 lines
843 B
C++
42 lines
843 B
C++
#include "global.h"
|
|
|
|
#include <string>
|
|
|
|
// 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
|
|
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 == "" )
|
|
return external;
|
|
|
|
return variable;
|
|
}
|
|
}
|
|
|
|
void compiler( char filename[] ) {
|
|
getTok();
|
|
|
|
}
|