#include "../lexer.h" #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; // You Must Be Call init_lib_core(); if (argc == 3 && strcmp(argv[2], "-nodebug") == 0) { log_set_level(NULL, LOG_LEVEL_ALL & ~LOG_LEVEL_DEBUG); } const char* file_name = "run.c"; if (argc == 2) { file_name = argv[1]; } FILE* fp = fopen(file_name, "r"); if (fp == NULL) { perror("open file failed"); return 1; } printf("open file success\n"); lexer_t lexer; strpool_t strpool; init_strpool(&strpool); init_lexer(&lexer, file_name, fp, (lexer_sread_fn)fread_s, &strpool); tok_t tok; while (1) { get_valid_token(&lexer, &tok); if (tok.sub_type == TOKEN_EOF) { break; } LOG_DEBUG("tk type `%s` in %s:%d:%d", get_tok_name(tok.sub_type), tok.loc.fname, tok.loc.line, tok.loc.col); // LOG_DEBUG("%s", tok.val.str); // printf("line: %d, column: %d, type: %3d, typename: %s\n", // lexer.line, lexer.index, tok.type, get_tok_name(tok.type)); } }