%{ #define WORD 1 #define TAG 2 %} word [^ \.,;:<>\t\n\r]+ tag <.*> %% {word} { return WORD; } {tag} { return TAG; } %% int main (int argc, char *argv[]) { int type; while ( type = yylex()) { if (WORD == type) printf ("Word: %s\n", yytext); if (TAG == type) printf ("Tag: %s\n", yytext); } }