The lexer hack

From Wikipedia, the free encyclopedia

When parsing computer programming languages, the lexer hack (as opposed to "a lexer hack") is a term in common use describing a common solution to the problems which arise when attempting to use a regular grammar-based lexer to classify tokens in ANSI C as either variable names or type names.

[edit] Solutions

The solution generally consists of feeding information from the parser's symbol table back into the lexer. This incestuous commingling of the lexer and parser is generally regarded as inelegant, which is why it is called a "hack".

This problem does not arise (and hence needs no "hack" in order to solve) when using lexerless parsing techniques.

[edit] Citations