aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 755a4e8f629f0cd71a7e49c465d3554c422b9cb9 (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
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>


#include "include/log.h"
#include "include/lexer.h"
// #include "include/tree.h"
// #include "include/parser.h"


int main(int argc, char* argv[]) {
   FILE *fsource;
   long fsource_size;
   char *source;

      fsource = fopen ("examples/hello.halk", "rb");
   if (!fsource) { 
      log_err("Source file not found");
      exit(1); 
   };

   fseek(fsource, 0L, SEEK_END);
   fsource_size = ftell(fsource);
   rewind(fsource);

   source = calloc(1, fsource_size + 1);

   if (!source) { 
      fclose(fsource); 
      log_err("Memory allocation failed");
      exit(1); 
   }

   if (1 != fread(source, fsource_size, 1, fsource)) {
      fclose(fsource); 
      free(source);
      log_err("Could not read source file");
      exit(1);
   }

   log_inf("Source file loaded");

   lexer_t* lexer = lexer_init(source);
   log_inf("Lexer created");

   log_inf("== BEGIN INPUT ==");
   log_inf(lexer->content);
   log_inf("=== END INPUT ===");

   token_t* token = NULL;

   while ((token = lexer_get_next_token(lexer)) != NULL) {
      printf("===\ntoken type: %d:\ntoken value: || %s ||\n===\n", token->type, token->value);
   }

   //parser_t* parser = parser_init(lexer);
   //log_inf("Parser created");

   //tree_t* tree = parser_parse(parser);
   //log_inf("Tree root created");

   //printf("TYPE: [%d]\n", tree->type);
   //printf("SIZE: [%d]\n", tree->data.subtree.size);

   fclose(fsource);

   log_inf("Source file closed");

   return 0;
}