aboutsummaryrefslogtreecommitdiffstats
path: root/test/littlesemantics/little.flex
diff options
context:
space:
mode:
authorlrg <lrg@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-10-20 10:38:22 +0000
committerlrg <lrg@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-10-20 10:38:22 +0000
commitf0198ebf9430d286ce7c9a53b703e967ce86481c (patch)
treeac069673f4a94e079bf12505c4f0a58baeea34ef /test/littlesemantics/little.flex
parenteb7c8587f462adca878088ef5f610c81734efc70 (diff)
downloadcompcert-f0198ebf9430d286ce7c9a53b703e967ce86481c.tar.gz
compcert-f0198ebf9430d286ce7c9a53b703e967ce86481c.zip
interpreter for "little"
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@119 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/littlesemantics/little.flex')
-rw-r--r--test/littlesemantics/little.flex41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/littlesemantics/little.flex b/test/littlesemantics/little.flex
new file mode 100644
index 00000000..57a1e0cd
--- /dev/null
+++ b/test/littlesemantics/little.flex
@@ -0,0 +1,41 @@
+%option noyywrap
+%{
+#include <string.h>
+#include "little.tab.h"
+extern char* lextext;
+extern int lexnum;
+%}
+
+
+DIGIT [0-9]
+ID [A-Za-z_][A-Za-z_0-9]*
+
+%%
+
+-?{DIGIT}+ { lexnum = atoi(yytext); return NUM; }
+"while" { return T_WHILE; }
+"do" { return T_DO; }
+"done" { return T_DONE; }
+"end" { return T_END; }
+"in" { return T_IN; }
+"skip" { return T_SKIP; }
+"variables" {return T_VARIABLES; }
+":=" {return T_ASSIGN; }
+">" {return T_GT; }
+";" {return T_SCOLUMN;}
+"+" {return T_PLUS;}
+"(" {return T_OPEN;}
+")" {return T_CLOSE;}
+"{" {return T_OPEN_B;}
+"}" {return T_CLOSE_B;}
+[ \t\n]
+{ID} { if(!(lextext =(char*)malloc(yyleng*sizeof(char)))) {
+ printf("failed memory allocation for variable %s", yytext);
+ exit(-1);
+ }
+ memcpy(lextext, yytext, yyleng);
+ return(ID);
+}
+
+%%
+