]> khamidou — GitHub mirrors - mojo.git/commitdiff
added a raw mode to the interpreter generator, similar to %{ and %} for flex
authorkhamidou <khamidou@gmail.com>
Tue, 19 Jan 2010 11:39:43 +0000 (12:39 +0100)
committerkhamidou <khamidou@gmail.com>
Tue, 19 Jan 2010 11:39:43 +0000 (12:39 +0100)
compiler.c
lexer.l
tests/basic.mj
tests/basic.mj~

index eb959625a68748662b6a8edafc2fe56a2afa24ac..38fd5c27456909f51325b9edb7e334ab0a6bc913 100644 (file)
@@ -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 <stdio.h>
@@ -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 67cf0ddf15fc79852ad2ed72543ca9281ef67d55..e3469967dd22027bee17e1bd6484a9bb75a0a1ea 100644 (file)
--- 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;        }
-<<EOF>>                { exit(0);}
+<<EOF>>                { return; }
+\%\{           { BEGIN(raw); }
+<raw>\%\}              { BEGIN(INITIAL); }
+<raw>.+       { printf("%s", yytext); }
index 90b8f8d55cd66910436fce859fb04c9fceb92df3..91479de9df999116c0c11007e8124b7c851753b9 100644 (file)
@@ -1 +1,5 @@
+%{
+       /* Everything is supposed to be under control */
+%}
+z := truc
 Lexer yylex;
index e3196f6fed4f91d189654d6cc953b4f86324877a..90b8f8d55cd66910436fce859fb04c9fceb92df3 100644 (file)
@@ -1,2 +1 @@
 Lexer yylex;
-Lexer with very long parameters;
\ No newline at end of file