41 lines
993 B
C
41 lines
993 B
C
|
|
#include "../lexer/lexer.h"
|
||
|
|
#include "../parser/parser.h"
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
|
||
|
|
static char* read_file(const char *filename) {
|
||
|
|
FILE *file = fopen(filename, "r");
|
||
|
|
if (!file) return NULL;
|
||
|
|
fseek(file, 0, SEEK_END);
|
||
|
|
long size = ftell(file);
|
||
|
|
fseek(file, 0, SEEK_SET);
|
||
|
|
char *content = malloc(size + 1);
|
||
|
|
size_t read_bytes = fread(content, 1, size, file); (void)read_bytes;
|
||
|
|
content[size] = '\0';
|
||
|
|
fclose(file);
|
||
|
|
return content;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
char *source = read_file("examples/11_TowerOfHanoiStatic.java");
|
||
|
|
if (!source) {
|
||
|
|
printf("Failed to read file\n");
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
RavaLexer_t *lexer = rava_lexer_create(source);
|
||
|
|
RavaParser_t *parser = rava_parser_create(lexer);
|
||
|
|
rava_parser_parse(parser);
|
||
|
|
|
||
|
|
if (parser->had_error) {
|
||
|
|
printf("Parse error: %s\n", parser->error_message);
|
||
|
|
free(source);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
printf("Parsed successfully!\n");
|
||
|
|
|
||
|
|
free(source);
|
||
|
|
return 0;
|
||
|
|
}
|