Lexers typically operate by using simple regular expression to recognise tokens in the input stream. For example, a NAME might be any alphabetical character or the underscore followed by any number of any alphanumeric character or the underscore. This could be represented compactly by the string [a-zA-Z_][a-zA-Z_0-9]+. This means "any character a-z, A-Z or _, then 0 or more of a-z, A-Z, _ or 0-9." Regular expressions are a simple way of representing complex problems. What they cannot do is represent structures such as "n opening parentheses, followed by a statement, followed by n closing parentheses." context free grammar provide the tools to recognise such things; this is, in fact, what a parser? does.