I really love to Chug Jug with you

This commit is contained in:
ItzzCode 2022-10-22 01:58:36 -04:00
parent 8d1504a6a7
commit 0d50c28054
3 changed files with 4 additions and 55 deletions

View File

@ -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())
}

View File

@ -1,4 +1,5 @@
#pragma once
#include <iostream>
#define DEBUG 1
#if DEBUG == 1

View File

@ -1,5 +1,3 @@
#include <iostream>
#include "compiler.cpp"
#include "global.h"