diff --git a/headers/lexer.h b/headers/lexer.h index 09ac0b7..04bc7de 100644 --- a/headers/lexer.h +++ b/headers/lexer.h @@ -4,33 +4,35 @@ #include //list of keywords + +//types denoted by the index within the enum class +//this is so its easy to pass this info to the parser enum class Keywords { - identifier, - integer, - floatpnt, - string, - character, - boolean, - plus, - minus, - multiply, - divide, - l_Paren, - r_Paren, - l_Brace, - r_Brace, - l_Brack, - r_Brack, - semicolon, - end_of_file, - unknown + identifier, //type 0 + integer, //type 1 + floatpnt, //type 2 + string, //type 3 + character, //type 4 + boolean, //type 5 + plus, //type 6 + minus, //type 7 + multiply, //type 8 + divide, //type 9 + l_Paren, //type 10 + r_Paren, //type 11 + l_Brace, //type 12 + r_Brace, //type 13 + l_Brack, //type 14 + r_Brack, //type 15 + semicolon, //type 16 + end_of_file, //type 17 + unknown //type 18 }; struct Token { Keywords type; std::string value; - Token(Keywords type, std::string value) : type(type), value(value) {} }; diff --git a/lexerOutput.txt b/lexerOutput.txt new file mode 100644 index 0000000..fdfbd69 --- /dev/null +++ b/lexerOutput.txt @@ -0,0 +1,9 @@ +Type: 0, Value: int +Type: 0, Value: main +Type: 10, Value: ( +Type: 11, Value: ) +Type: 12, Value: { +Type: 0, Value: return +Type: 1, Value: 0 +Type: 16, Value: ; +Type: 13, Value: } diff --git a/profaneCompiler b/profaneCompiler index 0cb9e7c..2f9047a 100755 Binary files a/profaneCompiler and b/profaneCompiler differ diff --git a/src/lexer.cpp b/src/lexer.cpp index caaedb2..7644b12 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -49,7 +49,7 @@ Lexer::Lexer(const std::string &input) { Token Lexer::getNextToken() { while (currentChar != '\0') { - std::cout << currentChar << std::endl; + //std::cout << currentChar << std::endl; if (std::isspace(currentChar)) { skipWhiteSpace(); diff --git a/src/profaneCompiler.cpp b/src/profaneCompiler.cpp index 26be998..c03f47a 100644 --- a/src/profaneCompiler.cpp +++ b/src/profaneCompiler.cpp @@ -5,6 +5,10 @@ #include "/home/mason/code-shit/ProfaneC/headers/lexer.h" +//overloads the << operator to output token type as an integer +//followed by the token value +//the integers corrispond to the order defined in the Keywords enum class +//reference lexer.h for map of token types to indecies std::ostream& operator<<(std::ostream& os, const Token& token) { os << "Type: " << static_cast(token.type) << ", Value: " << token.value; return os; @@ -44,5 +48,13 @@ int main() { std::cout << tokenVec.at(i) << std::endl; } + std::ofstream file_out("/home/mason/code-shit/ProfaneC/lexerOutput.txt"); + + if (file_out.is_open()) { + for (int i = 0; i < tokenVec.size(); i++) { + file_out << tokenVec.at(i) << std::endl; + } + } + return 0; } \ No newline at end of file