Implementing a Lexer in C++

01 January 1989

New Image

Current parsing technology is an object-oriented disaster. Although the theory underlying lexes and parsers is quite elegant, the implementations are usually a mess of global variables, global functions, unions, and explicit type casts. Indeed, in a typical lexer or parser, there is in fact no object called "lexer" or "parser." In this paper, we use C++ to make the implementation of a lexer for a fragment of C++ as elegant as the underlying theory.