Lex is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt.
Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language.
Prerequisite: Flex (Fast lexical Analyzer Generator)
Input: Hello everyone Output: 2 Input: This is GeeksforGeeks Output: 3
Note: The words can consist of lowercase characters, uppercase characters and digits.
Below is the implementation to count the number of words.