47 lines
968 B
C
47 lines
968 B
C
#include "../lexer.h"
|
|
#include <stdio.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;
|
|
|
|
const char* file_name = "test_lexer.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, "test_lexter.c", 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));
|
|
}
|
|
}
|