AAAAAAAAAAAAAAAAUUUUUUUUUUGGGGGGGGGGGGGGHHHHHHHHHHHHH
This commit is contained in:
parent
cbc97864c9
commit
2f69d187f2
52
compiler.cpp
52
compiler.cpp
@ -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
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
type tokenType;
|
||||
char* tokenValue;
|
||||
std::string identifierStr; // filled if string
|
||||
long NumVal; // filled if integer
|
||||
|
||||
tokens( type aTokenType, char* aTokenValue ) {
|
||||
tokenType = aTokenType;
|
||||
tokenValue = aTokenValue;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
tokens getTok( char code[] ) {
|
||||
if( code[0] == '#' )
|
||||
return tokens(tokens::comment, "");
|
||||
return tokens(tokens::comment, "");
|
||||
}
|
||||
|
||||
void compiler( char filename[] ) {
|
||||
std::cout << getTok(filename).tokenType << ' ' << getTok(filename).tokenValue;
|
||||
getTok();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user