%{ #include #include #include #include "analyse.h" #include "conf_yacc.h" /* Numero de la ligne courante */ int yylineno; /* Traitement des messages d'erreur */ void set_error(char * s); #define ERRLEN 1024 char err_str[ERRLEN]=""; /* Stockage des chaines */ char YY_PARSED_STRING[MAXSTRLEN]; void YY_BUFFER_APPEND(char * s){ strncat( YY_PARSED_STRING,s, MAXSTRLEN); } void YY_BUFFER_RESET(void){ int i; for (i=0;i{LETTER}({IDENTIFIER_CHAR})* {/* identifier */ DEBUG_LEX("[bloc:%s]\n",yytext); strncpy(yylval.str_val,yytext,MAXSTRLEN); BEGIN BLOC; return IDENTIFIER;} "{" {/* identifier */ DEBUG_LEX("BEGIN_BLOCK\n",yytext); BEGIN INBLOC;return BEGIN_BLOCK;} {LETTER}({IDENTIFIER_CHAR})* {/* identifier */ DEBUG_LEX("[id:%s",yytext);strncpy(yylval.str_val,yytext,MAXSTRLEN); BEGIN AFFECT;return IDENTIFIER;} "}" {/* identifier */ DEBUG_LEX("END_BLOCK\n",yytext); BEGIN YY_INIT;return END_BLOCK;} "=" {/* identifier */ DEBUG_LEX(" , ",yytext); BEGIN VALUE;return AFFECTATION;} "\"" {BEGIN STRING1;DEBUG_LEX("value:<");YY_BUFFER_RESET();} /* ouverture string 1 */ "'" {BEGIN STRING2;DEBUG_LEX("value:<");YY_BUFFER_RESET();} /* ouverture string 2 */ ({VAL_CHAR})+ {/* valeur */DEBUG_LEX("value:%s",yytext);BEGIN ENDVALUE;strncpy(yylval.str_val,yytext,MAXSTRLEN); return KEYVALUE;} ";" {DEBUG_LEX("]\n");BEGIN INBLOC;return END_AFFECT;} \\ {BEGIN ESC1;} "\"" {DEBUG_LEX(">");strncpy(yylval.str_val,YY_PARSED_STRING,MAXSTRLEN);BEGIN ENDVALUE;/* chaine finie */ return KEYVALUE;} \n {snprintf(err_str,ERRLEN,"line %d: missing closing quote.",yylineno,*yytext); set_error(err_str);yylineno++;return _ERROR_;} . {YY_BUFFER_APPEND(yytext); DEBUG_LEX("%c",*yytext);/* caractere de la chaine */} \n BEGIN STRING1;yylineno++;/* ignore un saut de ligne echappe*/ . {DEBUG_LEX("%c",*yytext);YY_BUFFER_APPEND(yytext);BEGIN STRING1;/* caractere de la chaine */} "'" {DEBUG_LEX(">");strncpy(yylval.str_val,YY_PARSED_STRING,MAXSTRLEN);BEGIN ENDVALUE;/* chaine finie */ return KEYVALUE;} \n {snprintf(err_str,ERRLEN,"line %d: closing quote missing.",yylineno,*yytext); set_error(err_str);yylineno++;return _ERROR_;} . {YY_BUFFER_APPEND(yytext);DEBUG_LEX("%c",*yytext);/* caractere de la chaine */} {COMMENTAIRE} ;/* ignore */ {SPACE} ;/* ignore */ {NL} yylineno++;/* ignore */ . { snprintf(err_str,ERRLEN,"line %d: '%c' unexpected",yylineno,*yytext); set_error(err_str);return _ERROR_;} %% int yywrap(void){ return 1; }