From 3acac2a9d0401dc67bf5175b1be0645335fdd197 Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Thu, 16 May 2013 09:09:45 +0200 Subject: [PATCH] run mojo directly on a file --- interp.c | 4 ++-- interp.h | 2 +- main.c | 15 +++++++++++++-- tests/basic.mj | 8 ++------ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/interp.c b/interp.c index 603fc08..75cacae 100644 --- a/interp.c +++ b/interp.c @@ -22,10 +22,10 @@ extern int yyleng; extern FILE *yyin; extern char *yytext; -int compile_image(FILE *fp) +int compile_image() { - while(!feof(fp)) { + while(!feof(yyin)) { struct Object* ast = create_list_object(); // clone_object(list_object); struct Object* scope = create_list_object(); //clone_object(list_object); diff --git a/interp.h b/interp.h index 053d4ad..3c373e5 100644 --- a/interp.h +++ b/interp.h @@ -3,7 +3,7 @@ #include -int compile_image(FILE *fp); +int compile_image(); void execute(struct Object *ast); struct Object* execute_branch(struct Object *ast, struct Object *scope); diff --git a/main.c b/main.c index d6d451e..97f906d 100644 --- a/main.c +++ b/main.c @@ -2,11 +2,22 @@ #include "object.h" #include "interp.h" +#include "error.h" -int main() { +extern FILE *yyin; + +int main(int argc, char **argv) { + + yyin = stdin; + if(argc == 2) { + yyin = fopen(argv[1], "r"); + if (yyin == NULL) { + fail("unable to open file : %s", argv[1]); + } + } init_object_system(); puts("this is mojo."); - compile_image(stdin); + compile_image(); return 0; } diff --git a/tests/basic.mj b/tests/basic.mj index b14645c..2d22881 100644 --- a/tests/basic.mj +++ b/tests/basic.mj @@ -1,6 +1,2 @@ -%{ - /* Everything is supposed to be under control */ -%} -z := truc -s := 3 -Lexer yylex; +2 + 2 ; +2 + 2 ; -- 2.43.0