Alex - Lexer generator for Haskell

Alex is a lexer generator for Haskell. Please review its documentation for syntax and general use before reading this document.

One of the interesting features of Alex is that it allows the use of and creation of wrappers which embody a significant portion of the bullet plate code needed for a lexer. Four wrappers are provided with Alex: basic, posn, monad and gscan.

Typically, the monad wrapper is found to be a good compromise between complexity and usability. However, a simple modification to it, described here, adds significantly to its usability while minimally affecting the complexity.

The monadUser wrapper

Please note this wrapper is based on the monad wrapper included with Alex. The code is in the public domain.

Use in the Alex source file

In Alex, wrappers are chosen by the %wrapper directive. To use the monadUser wrapper, add the line

     %wrapper "monadUser"

after the initial code block in your Alex source file.

Additionally, two items must be defined in a code block (or imported), the Haskell type UserData and the variable userStartState which must be of type UserData.

The template directory

The monadUser wrapper is not provided with a vanilla installation of Alex, so must be installed in your own template directory.

This template directory must also contain the standard Alex templates.

First, create a directory alex in your home directory. Copy all of the files from \usr\lib\alex2.0.1 to alex. Then download the file AlexWrapper-monadUser and store it in the alex directory.

Running Alex

When running alex, you must tell it to search the new directory for its templates and wrappers. This is accomplished by the -t flag. Run Alex like this:

     alex -t ~/alex input.x
Last modified by Brett Giles
Last modified: Mon Aug 27 20:34:22 MDT 2007

Valid XHTML 1.0!