CFLAGS=-c -g
-OBJS=lex.yy.o object.o list.o error.o number.o compiler.o
+OBJS=lex.yy.o object.o list.o error.o number.o main.o interp.o
mojo: $(OBJS)
cc -o mojo $(OBJS) -lfl
cc $(CFLAGS) lex.yy.c
object.o: object.h object.c
-compiler.o: compiler.c compiler.h
+main.o: main.c
list.o: list.c
+interp.o: interp.c
number.o: number.c number.h
error.o: error.h error.c
rm *~
count:
- wc -l `ls *.[chl] -1 | grep -v lex.yy.c | grep -v queue`
\ No newline at end of file
+ wc -l `ls *.[chl] -1 | grep -v lex.yy.c | grep -v queue`
}
}
-int eval_image(FILE *fp)
+int compile_image(FILE *fp)
{
- struct Object* stack = clone_object(list_object);
- int r;
- while((r = yylex()) != T_EOF) {
- switch(r) {
- case NUMBER:
- {
- }
- default:
- break;
- }
- }
+ struct Object* ast = clone_object(list_object);
+ expression(ast);
+ display_ast(ast);
+}
+
+int expression(struct Object *ast) {
+
+ int r = yylex();
+ switch(r) {
+ case NUMBER:
+ puts("number here bro");
+ struct Object* obj = clone_object(number_object);
+ list_append(ast, obj);
+ return message(ast);
+ break;
+ default:
+ fail("Unexpected : %s", yytext);
+ break;
+ }
+}
+
+int message(struct Object *ast) {
+ int r = yylex();
+ switch(r) {
+ case SYMBOL:
+ printf("message : %s\n", yytext);
+ struct Object* obj = clone_object(base_object);
+ obj->type = T_MESSAGE;
+ obj->name = strdup(yytext);
+ list_append(ast, obj);
+ expression(ast);
+ break;
+
+ case SEMICOLON:
+ return 0;
+ break;
+
+ default:
+ fail("Expected symbol, got : %s", yytext);
+ break;
+ }
+
+}
+
+void display_ast(struct Object *ast) {
+
+ int length = mojo_list_length(ast->value.l_value);
+
+ printf("ast->value.lv: %x, ast len: %d\n", ast->value.l_value, length);
}
[0-9]+ { return NUMBER; }
-; { return COMMA; }
+; { return SEMICOLON; }
:= { return AFFECTATION; }
\"[:alnum:]+\" { return STRING; }
[a-zA-Z][a-zA-Z0-9]* { return SYMBOL; }
break;
case T_LIST:
+ new->value.l_value = mojo_list_init();
for (i = 0; i < mojo_list_length(o->value.l_value); i++) {
struct Object *t = clone_object((struct Object *) list_nth(o, i));