1 %{ 2 3 #include <math.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include "goomsl.h" 7 #include "goomsl_private.h" 8 #include "goomsl_yacc.h" 9 void yyerror(char *); 10 void yyparse(void); 11 12 GoomSL *currentGoomSL; 13 static int string_size; 14 static char string[1024]; 15 %} 16 17 DIGIT [0-9] 18 XDIGIT [0-9a-f] 19 ID [a-zA-Z_@&][a-zA-Z0-9_\.]* 20 21 %S C_COMMENT 22 %S LINE_COMMENT 23 %S STRING 24 25 %% 26 27 <LINE_COMMENT,C_COMMENT,INITIAL>^[ \t]*\n { ++currentGoomSL->num_lines; /* Ignore empty lines */ } 28 <LINE_COMMENT,C_COMMENT,INITIAL>^[ \t]*"//"[^\n]*\n { ++currentGoomSL->num_lines; /* Ignore empty lines */ } 29 30 <LINE_COMMENT>\n { ++currentGoomSL->num_lines; yylval.charValue=*yytext; BEGIN INITIAL; return '\n'; } 31 <INITIAL>\n { ++currentGoomSL->num_lines; yylval.charValue=*yytext; return '\n'; } 32 33 <C_COMMENT>"*/" { BEGIN INITIAL; } 34 <C_COMMENT>\n { ++currentGoomSL->num_lines; } 35 <C_COMMENT,LINE_COMMENT>. { /* eat up comment */ } 36 37 <INITIAL>"#RST_LINE#" { currentGoomSL->num_lines = 0; } 38 <INITIAL>"#FILE ".*"#" { currentGoomSL->num_lines = 0; /* printf("%s\n", yytext); */ } 39 <INITIAL>"#"[^\n]* { /* ignore preprocessor lines */ } 40 41 <INITIAL>"/*" { BEGIN C_COMMENT; } 42 <INITIAL>"//" { BEGIN LINE_COMMENT; } 43 <INITIAL>\" { BEGIN STRING; string_size=0; } 44 45 <STRING>"\\n" { string[string_size++] = '\n'; } 46 <STRING>"\\\"" { string[string_size++] = '\"'; } 47 <STRING>\" { /* fin de la chaine: on cree le pointeur qui va bien */ 48 unsigned int tmp; 49 BEGIN INITIAL; 50 string[string_size]=0; 51 tmp = gsl_malloc(currentGoomSL, string_size+1); 52 strcpy((char*)currentGoomSL->ptrArray[tmp],string); 53 sprintf(yylval.strValue, "0x%08x", tmp); 54 return LTYPE_PTR; 55 } 56 <STRING>. { string[string_size++] = *yytext; } 57 58 <INITIAL>"float" { return FLOAT_TK; } 59 <INITIAL>"int" { return INT_TK; } 60 <INITIAL>"boolean" { return INT_TK; } 61 <INITIAL>"ptr" { return PTR_TK; } 62 <INITIAL>"string" { return PTR_TK; } 63 <INITIAL>"declare" { return DECLARE; } 64 <INITIAL>"external" { return EXTERNAL; } 65 <INITIAL>"struct" { return STRUCT; } 66 <INITIAL>"not" { return NOT; } 67 <INITIAL>"while" { return WHILE; } 68 <INITIAL>"do" { return DO; } 69 <INITIAL>"for" { return FOR; } 70 <INITIAL>"in" { return IN; } 71 <INITIAL>"true" { strncpy(yylval.strValue, "1", 2047); return LTYPE_INTEGER; } 72 <INITIAL>"false" { strncpy(yylval.strValue, "0", 2047); return LTYPE_INTEGER; } 73 <INITIAL>{ID} { strncpy(yylval.strValue, yytext, 2047); return LTYPE_VAR; } 74 <INITIAL>{DIGIT}+ { strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } 75 <INITIAL>\'.\' { sprintf(yylval.strValue, "%d", (int)yytext[1]); return LTYPE_INTEGER; } 76 <INITIAL>"0x"{XDIGIT}+ { strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } 77 <INITIAL>{DIGIT}+"."{DIGIT}* { strncpy(yylval.strValue, yytext, 2047); return LTYPE_FLOAT; } 78 <INITIAL>{DIGIT}+"%" { sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return LTYPE_FLOAT; } 79 <INITIAL>"+=" { return PLUS_EQ; } 80 <INITIAL>"*=" { return MUL_EQ; } 81 <INITIAL>"-=" { return SUB_EQ; } 82 <INITIAL>"/=" { return DIV_EQ; } 83 <INITIAL>"<=" { return LOW_EQ; } 84 <INITIAL>">=" { return SUP_EQ; } 85 <INITIAL>"!=" { return NOT_EQ; } 86 <INITIAL>"<>" { return NOT_EQ; } 87 <INITIAL>[ \t]+ /* eat up whitespace */ 88 <INITIAL>. { yylval.charValue = *yytext; return *yytext; } 89 90 %% 91 92 93 int yywrap(void) { return 1; yyunput(0,0); } 94 95