diff options
Diffstat (limited to 'source/fajr')
| -rw-r--r-- | source/fajr/fajr_main.c | 41 | ||||
| -rw-r--r-- | source/fajr/fajr_main.h | 6 |
2 files changed, 47 insertions, 0 deletions
diff --git a/source/fajr/fajr_main.c b/source/fajr/fajr_main.c new file mode 100644 index 0000000..fc7be4a --- /dev/null +++ b/source/fajr/fajr_main.c | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #define BASE_UNITY | ||
| 2 | #include "base/base_include.h" | ||
| 3 | #include "fajr_lexer/fajr_lexer.h" | ||
| 4 | #include "fajr_parser/fajr_parser.h" | ||
| 5 | |||
| 6 | #include "fajr_lexer/fajr_lexer.c" | ||
| 7 | #include "fajr_parser/fajr_parser.c" | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char **argv) | ||
| 11 | { | ||
| 12 | mem_arena *global = arena_create(GiB(1)); | ||
| 13 | if (argc < 2) { | ||
| 14 | print("Usage: program <file>\n"); | ||
| 15 | return 1; | ||
| 16 | } | ||
| 17 | |||
| 18 | i32 fd = open(argv[1], O_RDONLY); | ||
| 19 | if (fd < 0) { | ||
| 20 | print("Error: Cannot open file\n"); | ||
| 21 | return 1; | ||
| 22 | } | ||
| 23 | |||
| 24 | u8 input[4096]; | ||
| 25 | u64 bytes_read; | ||
| 26 | bytes_read = read(fd, input, sizeof(input)); | ||
| 27 | |||
| 28 | string8 buffer = {0}; | ||
| 29 | |||
| 30 | buffer.data = input; | ||
| 31 | buffer.size = bytes_read; | ||
| 32 | |||
| 33 | token_list *List = PushStruct(global, token_list); | ||
| 34 | concrete_syntax_tree *Tree = PushStruct(global, concrete_syntax_tree); | ||
| 35 | |||
| 36 | Lex(&buffer, global, List); | ||
| 37 | Parse(global, List, Tree); | ||
| 38 | |||
| 39 | close(fd); | ||
| 40 | return 0; | ||
| 41 | } | ||
diff --git a/source/fajr/fajr_main.h b/source/fajr/fajr_main.h new file mode 100644 index 0000000..835ab65 --- /dev/null +++ b/source/fajr/fajr_main.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef FAJR_MAIN_H | ||
| 2 | #define FAJR_MAIN_H | ||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | #endif /* FAJR_MAIN_H */ | ||
