aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 3c1b8b86c1e7771f57baeb3fb76d63b68697788f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>

#include "include/util.h"
#include "include/hlkt.h"
#include "include/source.h"
#include "include/token.h"
#include "include/pp.h"
#include "include/lexer.h"
#include "include/parser.h"

int main(int argc, char* argv[]) {
   char*    src;     /* the source "code" */
   pp_t*    pp;
   lexer_t* lexer;
   parser_t* parser;

   /* get source */
   src = source_get(argv[1]); 
   HLKT_ASS(src);
   log_dbg("source gotten");
   log_inf("source: %s", src);

   /* create pre-processor */
   pp = pp_init(src);
   HLKT_ASS(pp);
   log_dbg("preprocessor created");

   /* pre-process source */
   pp_run(pp);
   free(src);
   src = pp->psrc;
   log_inf("pre-processed source: %s", pp->psrc);
   /* destroy pre-processor */
   pp_destroy(pp);
   HLKT_ASS(src);
   log_dbg("preprocessor ran");

   /* create lexer */
   lexer = lexer_init(src);
   HLKT_ASS(lexer);
   HLKT_ASS(lexer->src == src);
   log_dbg("lexer created");

   /* run lexer */
   lexer_run(lexer);
   log_dbg("lexer ran");

   /* Create the parser from the lexer's tokens. */
   parser = parser_init(lexer->tokenl);
   parser_run(parser);
   tree_print(parser->tree, 0);

   /* Clean up parser stuff. */
   token_destroy(lexer->tokenl);
   lexer_destroy(lexer);
   tree_destroy(parser->tree);
   parser_destroy(parser);
   free(src);

   HLKT_LOG();

   return 0;
}