Files
scc/libs/lexer/src/main.c
zzy 4144f7841c refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr
- 更新头文件和源文件中的指针初始化和比较操作
- 修改测试文件中的相关断言检查
- 更新AST定义文件中的注释说明
2026-04-05 20:18:09 +08:00

71 lines
1.8 KiB
C

#include <lexer_log.h>
#include <scc_lexer.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(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;
}