- 重命名和重构了多个文件,包括 lexer、parser 和 AST 相关代码 - 添加了日志功能,使用 LOG_* 宏替代原有的 error 和 warn 函数 - 优化了错误处理和内存分配方式 - 调整了代码结构,提高了模块化和可读性
53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
#include "../lexer.h"
|
|
#include <stdio.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;
|
|
// 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;
|
|
init_lexer(&lexer, file_name, fp, (lexer_sread_fn)fread_s);
|
|
tok_t tok;
|
|
|
|
while (1) {
|
|
get_valid_token(&lexer, &tok);
|
|
if (tok.type == TOKEN_EOF) {
|
|
break;
|
|
}
|
|
// printf("line: %d, column: %d, type: %3d, typename: %s\n",
|
|
// lexer.line, lexer.index, tok.type, get_tok_name(tok.type));
|
|
}
|
|
}
|