#include <errno.h>
#include <string.h>
-#include "lexer_t.h"
+#include "lexer.h"
#include "token_t.h"
+#include "type_hash.h"
+#include "parser.h"
#if 0
static
#endif
static
-void compile(const char *fname)
+translation_unit_t *do_parsing(const char *fname)
{
- lexer_t lexer;
- token_t token;
+ FILE *in = fopen(fname, "r");
+ if(in == NULL) {
+ fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
+ exit(1);
+ }
+
+ lexer_open_stream(in, fname);
+
+ translation_unit_t *unit = parse();
+
+ fclose(in);
+ return unit;
+}
+
+static
+void lextest(const char *fname)
+{
FILE *in = fopen(fname, "r");
if(in == NULL) {
fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
exit(1);
}
- lexer_init(&lexer, in, fname);
+ lexer_open_stream(in, fname);
do {
- lexer_next_token(&lexer, &token);
- print_token(stdout, &token);
+ lexer_next_preprocessing_token();
+ print_token(stdout, &lexer_token);
puts("");
- } while(token.type != T_EOF);
+ } while(lexer_token.type != T_EOF);
- lexer_destroy(&lexer);
fclose(in);
}
+void write_fluffy_decls(translation_unit_t *unit);
+
int main(int argc, char **argv)
{
init_symbol_table();
init_tokens();
+ init_lexer();
+ init_types();
+ init_typehash();
+ init_ast();
+ init_parser();
+
+ if(argc > 2 && strcmp(argv[1], "--lextest") == 0) {
+ lextest(argv[2]);
+ return 0;
+ }
+
+ if(argc > 2 && strcmp(argv[1], "--print-ast") == 0) {
+ translation_unit_t *unit = do_parsing(argv[2]);
+ ast_set_output(stdout);
+ print_ast(unit);
+ return 0;
+ }
for(int i = 1; i < argc; ++i) {
- compile(argv[i]);
+ translation_unit_t *unit = do_parsing(argv[i]);
+ write_fluffy_decls(unit);
}
+ exit_parser();
+ exit_ast();
+ exit_typehash();
+ exit_types();
+ exit_lexer();
exit_tokens();
exit_symbol_table();
return 0;