slr/slr.c

38 lines
854 B
C
Raw Permalink Normal View History

2024-05-16 19:40:44 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
2024-05-16 20:03:04 +02:00
#include "lexer.h"
2024-05-22 12:12:48 +02:00
#include "parser.h"
2024-05-16 19:40:44 +02:00
long long get_file_length(FILE *file)
{
fseeko(file, 0, SEEK_END);
long long length = ftello(file);
fseeko(file, 0, SEEK_SET);
return length;
}
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "\033[1;37mslr:\033[0m \033[1;31mfatal error:\033[0m no input files\ninterpretation termined.\n");
2024-05-22 12:12:48 +02:00
return 1;
2024-05-16 19:40:44 +02:00
}
FILE *file = fopen(argv[1], "r");
2024-05-22 12:12:48 +02:00
if (!file) {
perror("fopen");
return 1;
}
2024-05-16 19:40:44 +02:00
long long length = get_file_length(file);
char *buf = malloc(length * sizeof(char));
fread(buf, 1, length, file);
fclose(file);
buf[length + 1] = '\0';
Token *tokens = lexer(buf);
2024-05-22 12:12:48 +02:00
for(size_t i = 0; tokens[i].type != END_OF_TOKENS; i++){
print_token(tokens[i]);
}
2024-05-16 19:40:44 +02:00
}