refactor(lex_parser): 移除旧的词法解析器实现并更新依赖
移除了 libs/lex_parser 目录下的所有头文件和源文件,包括: - lex_parser.h 和 lex_parser.c 核心解析功能 - 所有测试文件(test_char.c, test_identifier.c, test_number.c, test_skip_block_comment.c, test_skip_line.c, test_string.c) 更新了 lexer 模块的依赖配置,将 lex_parser 替换为 sstream, 同时更新了 lexer.h 中的相关包含头文件和数据结构定义, 简化了 scc_lexer_t 结构体的字段。
This commit is contained in:
66
libs/lexer/src/main.c
Normal file
66
libs/lexer/src/main.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <lexer.h>
|
||||
#include <lexer_log.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
/// 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(NULL, LOG_LEVEL_ALL);
|
||||
} else {
|
||||
// FIXME it is a hack lexer_logger
|
||||
log_set_level(&__scc_lexer_log, LOG_LEVEL_NOTSET);
|
||||
log_set_level(NULL, 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_ref_ring(&stream);
|
||||
scc_lexer_init(&lexer, ref);
|
||||
scc_lexer_tok_t token;
|
||||
|
||||
while (1) {
|
||||
scc_lexer_get_valid_token(&lexer, &token);
|
||||
if (token.type == SCC_TOK_EOF) {
|
||||
break;
|
||||
}
|
||||
LOG_DEBUG("get token [%-8s] `%s` at %s:%d:%d",
|
||||
scc_get_tok_name(token.type),
|
||||
scc_cstring_as_cstr(&token.lexeme), token.loc.name,
|
||||
token.loc.line, token.loc.col);
|
||||
// LOG_DEBUG("%s", token.val.str);
|
||||
// printf("line: %d, column: %d, type: %3d, typename: %s\n",
|
||||
// lexer.line, lexer.index, token.type,
|
||||
// scc_get_tok_name(token.type));
|
||||
}
|
||||
scc_sstream_drop_ring(ref);
|
||||
scc_sstream_drop(&stream);
|
||||
|
||||
LOG_INFO("Lexer is Ok...");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user