#include "../lexer/lexer.h" #include "../parser/parser.h" #include "../semantic/semantic.h" #include "../ir/ir.h" #include "../ir/ir_gen.h" #include "../runtime/runtime.h" #include #include 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/19_BreakContinue.java"); if (!source) { printf("Failed\n"); return 1; } RavaLexer_t *l = rava_lexer_create(source); RavaParser_t *p = rava_parser_create(l); RavaASTNode_t *ast = rava_parser_parse(p); if (p->had_error) { printf("Parse: %s\n", p->error_message); return 1; } printf("Parse: OK\n"); RavaSemanticAnalyzer_t *a = rava_semantic_analyzer_create(); if (!rava_semantic_analyze(a, ast)) { printf("Semantic: %s\n", a->error_message); return 1; } printf("Semantic: OK\n"); RavaIRGenerator_t *g = rava_ir_generator_create(a); RavaProgram_t *prog = rava_ir_generate(g, ast); if (!prog) { printf("IR failed\n"); return 1; } printf("IR: OK\nOutput:\n"); RavaVM_t *vm = rava_vm_create(prog); if (!rava_vm_execute(vm, "BreakContinue", "main")) { printf("Runtime: %s\n", vm->error_message); return 1; } printf("\nExecution: OK\n"); return 0; }