#include #include #include #include #include #include /// gcc -g ../lexer.c ../token.c test_lexer.c -o test_lexer /* tok_tConstant { int have; union { char ch; int i; float f; double d; long long ll; char* str; }; }; */ int g_num; int g_num_arr[3]; int main(int argc, char *argv[]) { // int num = 0; if (argc == 3 && strcmp(argv[2], "--debug") == 0) { log_set_level(nullptr, LOG_LEVEL_ALL); } else { // FIXME it is a hack lexer_logger log_set_level(&__scc_lexer_log, LOG_LEVEL_NOTSET); log_set_level(nullptr, LOG_LEVEL_INFO | LOG_LEVEL_WARN | LOG_LEVEL_ERROR | LOG_LEVEL_FATAL); } const char *file_name = __FILE__; if (argc == 2) { file_name = argv[1]; } scc_lexer_t lexer; scc_sstream_t stream; scc_sstream_init(&stream, file_name, 16); scc_sstream_ring_t *ref = scc_sstream_to_ring(&stream); scc_lexer_init(&lexer, ref); scc_lexer_tok_t token; scc_lexer_tok_ring_t *tok_ring = scc_lexer_to_ring(&lexer, 16, false); int ok; while (1) { // scc_lexer_get_valid_token(&lexer, &token); // if (token.type == SCC_TOK_EOF) { // break; // } scc_ring_next_consume(*tok_ring, token, ok); if (!ok) { break; } LOG_INFO("get token [%-8s] `%s` at %s:%d:%d", scc_get_tok_name(token.type), scc_str_as_cstr(&token.lexeme), token.loc.name, token.loc.line, token.loc.col); scc_str_drop(&token.lexeme); } scc_sstream_drop_ring(ref); scc_sstream_drop(&stream); LOG_INFO("Lexer is Ok..."); return 0; }