slr/slr.c

40 lines
953 B
C
Raw 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
}
2024-10-22 02:20:14 +02:00
/* https://github.com/CobbCoding1/unnamed-lang/commit/10ecba484a0b47110c19b2604500c9ae49f84c52 */