34 lines
1005 B
C
34 lines
1005 B
C
#include "../parser.h"
|
|
#include "../ast/ast.h"
|
|
#include "../symtab/symtab.h"
|
|
#include <stdio.h>
|
|
|
|
// gcc -g ../parser.c ../../lexer/lexer.c ../ast/ast.c ../ast/block.c ../ast/decl.c ../ast/expr.c ../ast/func.c ../ast/program.c ../ast/stmt.c ../ast/term.c ../symtab/hashmap.c ../symtab/scope.c ../symtab/symtab.c test_parser.c -o test_parser
|
|
// gcc -g test_parser.c -L../.. -lfrontend -o test_parser
|
|
int main(int argc, char** argv) {
|
|
const char* file_name = "test_file.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");
|
|
|
|
struct Lexer lexer;
|
|
init_lexer(&lexer, file_name, fp, (lexer_sread_fn)fread_s);
|
|
|
|
struct SymbolTable symtab;
|
|
init_symtab(&symtab);
|
|
|
|
struct parser parser;
|
|
init_parser(&parser, &lexer, &symtab);
|
|
parse_prog(&parser);
|
|
|
|
printf("parse_end\n");
|
|
pnt_ast(parser.root, 0);
|
|
|
|
return 0;
|
|
} |