An Example of Lex


This is a very simple example of how to use Lex. The file ex.lex contains rules that match all five letter words that begin with a "p" and end with a "t". (This might be useful in solving a crossword puzzle!). Lex takes the specification and produces a file "lex.yy.c" that contains a subroutine "yylex()". This subroutine is called from main.c. Each time yylex() returns a word that matches our requirement, it is printed. When the entire input has been scanned, "yywrap()" is called by yylex(). This sets a flag indicating that we are done.