%{ #include #include #include extern char *yytext; extern int yylineno; extern int yylex(); extern void yyerror(char *s); %} %token HTML_OP HTML_CL HEAD_OP HEAD_CL BODY_OP BODY_CL PRE_OP PRE_CL %token I_OP I_CL P_OP P_CL BR SPS NL %token PURE_TEXT %token H_OP H_CL LINK SCRIPT_OP SCRIPT_CL AH_OP AN_OP A_CL %token CDIV_OP DIV_OP DIV_CL OTHERTAG_CL OTHERTAG_OP %type LexUnit %error-verbose %union { char *string; } %% Text: | Text LexUnit {if ($2 != NULL) {fprintf(stderr, "[%s] ", $2); free($2);}} ; LexUnit: HTML_OP | HTML_CL | HEAD_OP | HEAD_CL | BODY_OP | BODY_CL | PRE_OP | PRE_CL | I_OP | I_CL | P_OP | P_CL | BR | SPS | NL | H_OP | H_CL | LINK | SCRIPT_OP | SCRIPT_CL | AH_OP | AN_OP | A_CL | CDIV_OP | DIV_OP | DIV_CL | PURE_TEXT | error { yyerrok; yyclearin; } ; %% int main() { yyparse(); return EXIT_SUCCESS; } int yywrap( ) { /* utilise par yylex() traitement d'un seul fichier pour plusieurs fichiers, retourner 0 equivalent a %option noyywrap dans le fichier flex */ return 1; } void yyerror(char *s) { /* utilise par yyparse() */ fprintf(stderr, "\nl.%d %s: %s!!\n", yylineno, yytext, s); }