#include #include #include #include "Lexer.h" void printTokens(std::vector &tokens) { for(int i = 0;i &tokens, const char* code) { std::ofstream out("../cpp2.html"); std::string header = "\n" "\n" "\n" " \n" "\n" "\n"; out << header; unsigned codeInd = 0; for(int i = 0;i < tokens.size();i++) { while(code[codeInd] == ' ' || code[codeInd] == '\t' || code[codeInd] == '\n') { if(code[codeInd] == '\n') out << "
"; else out << " "; //else out << ++codeInd; } if(tokens[i].type == TokenType::NUMBER) { out << "" << tokens[i].value <<""; } else if(tokens[i].type == TokenType::STRING) { out << "" << tokens[i].lexeme <<""; } else if(tokens[i].type == TokenType::COMMENT) { out << "" << tokens[i].lexeme <<""; } else if(tokens[i].type <= TokenType::RIGHT_SHIFT_EQUAL) { out << "" << tokens[i].lexeme <<""; } else if(tokens[i].type <= TokenType::XOR_EQ) { out << "" << tokens[i].lexeme <<""; } else if(tokens[i].type <= TokenType::PRE_PRAGMA) { out << "" << tokens[i].lexeme <<""; } else { out << tokens[i].lexeme; } codeInd += tokens[i].lexeme.length(); } out << "\n\n"; out.close(); } int main() { char code[] = "#include\nbool isCapitalCase(char c)\n{\n return c >= 'A' && c <= 'Z';\n}\nm_KeyWordsTable[\"break\"] = TokenType::Break;\n// this is a comment test\n" "/* another one */"; Tokenizer tokenizer(code); std::vector tokens; if(tokenizer.tokenize(tokens)) { cpp2html(tokens, code); } //printTokens(tokens); return 0; }