Here are a number of short Lex programs to demonstrate what sorts of things you can do with Lex . Several of these programs are copied from the book lex & yacc by John R. Levine, Tony Mason, and Doug Brown, published by O'Reilly & Associates, 1992.
flex code to recognize
parts of speech, combined with a yacc program to recognize
the grammatical structure of the sentence.
yacc and flex portions of a simple calculator
program (copied from the O'Reilly book). the Makefile for all these.