From: khamidou Date: Tue, 19 Jan 2010 11:39:43 +0000 (+0100) Subject: added a raw mode to the interpreter generator, similar to %{ and %} for flex X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b87638f52141b163fae97846dd5d0d0dcb5aa132;p=mojo.git added a raw mode to the interpreter generator, similar to %{ and %} for flex --- diff --git a/compiler.c b/compiler.c index eb95962..38fd5c2 100644 --- a/compiler.c +++ b/compiler.c @@ -3,7 +3,9 @@ copyright (c) 2009 karim hamidou. This is a rough translator for a subset of mojo to C. - + It does no verifications whatsoever, everything is kept at the sole discretion + of the programmer. + */ #include @@ -32,6 +34,9 @@ int main(int argc, char **argv) int r; while((r = yylex()) != T_EOF) { switch(r) { + case EOF: + break; + case SYMBOL: symbol(); break; @@ -51,8 +56,12 @@ void symbol() int r = yylex(); switch(r) { + case EOF: + break; + case AFFECTATION: - printf("struct Object *%s = ", symname); + yylex(); + printf("struct Object *%s = %s;", symname, yytext); break; default: @@ -73,6 +82,10 @@ void symbol() while ((r = yylex()) && i < 4) { switch(r) { + case EOF: + goto loop_exit; + break; + case COMMA: break; @@ -83,6 +96,7 @@ void symbol() i++; } + loop_exit: if (i < 4) { while(i < 3) { printf("NULL,"); diff --git a/lexer.l b/lexer.l index 67cf0dd..e346996 100644 --- a/lexer.l +++ b/lexer.l @@ -3,6 +3,7 @@ %} %option yylineno +%s raw %% @@ -12,4 +13,7 @@ := { return AFFECTATION; } \"[:alnum:]+\" { return STRING; } [a-zA-Z][a-zA-Z0-9]* { return SYMBOL; } -<> { exit(0);} +<> { return; } +\%\{ { BEGIN(raw); } +\%\} { BEGIN(INITIAL); } +.+ { printf("%s", yytext); } diff --git a/tests/basic.mj b/tests/basic.mj index 90b8f8d..91479de 100644 --- a/tests/basic.mj +++ b/tests/basic.mj @@ -1 +1,5 @@ +%{ + /* Everything is supposed to be under control */ +%} +z := truc Lexer yylex; diff --git a/tests/basic.mj~ b/tests/basic.mj~ index e3196f6..90b8f8d 100644 --- a/tests/basic.mj~ +++ b/tests/basic.mj~ @@ -1,2 +1 @@ Lexer yylex; -Lexer with very long parameters; \ No newline at end of file