more work on parser
[cparser] / main.c
diff --git a/main.c b/main.c
index 81d4760..eb0c479 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,8 @@
 
 #include "lexer_t.h"
 #include "token_t.h"
+#include "type_hash.h"
+#include "parser.h"
 
 #if 0
 static
@@ -37,24 +39,25 @@ void get_output_name(char *buf, size_t buflen, const char *inputname,
 static
 void compile(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_init(&lexer, in, fname);
+       lexer_open_stream(in, fname);
 
+#if 0
+       token_t token;
        do {
-               lexer_next_token(&lexer, &token);
+               lexer_next_token(&token);
                print_token(stdout, &token);
                puts("");
        } while(token.type != T_EOF);
+#else
+       parse();
+#endif
 
-       lexer_destroy(&lexer);
        fclose(in);
 }
 
@@ -62,11 +65,21 @@ int main(int argc, char **argv)
 {
        init_symbol_table();
        init_tokens();
+       init_lexer();
+       init_types();
+       init_typehash();
+       init_ast();
+       init_parser();
 
        for(int i = 1; i < argc; ++i) {
                compile(argv[i]);
        }
 
+       exit_parser();
+       exit_ast();
+       exit_typehash();
+       exit_types();
+       exit_lexer();
        exit_tokens();
        exit_symbol_table();
        return 0;