summaryrefslogtreecommitdiff
path: root/source/fajr/fajr_main.c
blob: fc7be4aa1f3862815f06adad2dbdc71f2d9f8372 (plain)
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
#define BASE_UNITY
#include "base/base_include.h"
#include "fajr_lexer/fajr_lexer.h"
#include "fajr_parser/fajr_parser.h"

#include "fajr_lexer/fajr_lexer.c"
#include "fajr_parser/fajr_parser.c"

int
main(int argc, char **argv)
{
    mem_arena *global = arena_create(GiB(1));
    if (argc < 2) {
        print("Usage: program <file>\n");
        return 1;
    }

    i32 fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
        print("Error: Cannot open file\n");
        return 1;
    }

    u8 input[4096];
    u64 bytes_read;
    bytes_read = read(fd, input, sizeof(input));

    string8 buffer = {0};

    buffer.data = input;
    buffer.size = bytes_read;

    token_list *List = PushStruct(global, token_list);
    concrete_syntax_tree *Tree = PushStruct(global, concrete_syntax_tree);

    Lex(&buffer, global, List);
    Parse(global, List, Tree);

    close(fd);
    return 0;
}