Stanford University: Keith Schwarz's "FLEX in a Nutshell"
Read these notes. FLEX is a scanner generator. It produces a scanner, given a description of the patterns to be identified and actions to take for each token.
Click http://www.keithschwarz.com/cs143/WWW/sum2011/handouts/040_Flex_In_A_Nutshell.pdf link to open resource.