Alex User Guide

Chris Dornan

Isaac Jones

Simon Marlow


Alex is a tool for generating lexical analysers in Haskell, given a description of the tokens to be recognised in the form of regular expressions. It is similar to the tool lex or flex for C/C++.

Table of Contents

1. About Alex
1.1. Release Notes for version 3.0
1.2. Release Notes for version 2.2
1.3. Release Notes for version 2.1.0
1.4. Release Notes for version 2.0
1.4.1. Syntax changes
1.4.2. Changes in the form of an Alex file
1.4.3. Usage changes
1.4.4. Implementation changes
1.5. Reporting bugs in Alex
1.6. License
2. Introduction
3. Alex Files
3.1. Lexical syntax
3.2. Syntax of Alex files
3.2.1. Macro definitions
3.2.2. Rules Contexts Start codes
4. Regular Expression
4.1. Syntax of regular expressions
4.2. Syntax of character sets
5. The Interface to an Alex-generated lexer
5.1. Unicode and UTF-8
5.2. Basic interface
5.3. Wrappers
5.3.1. The "basic" wrapper
5.3.2. The "posn" wrapper
5.3.3. The "monad" wrapper
5.3.4. The "monadUserState" wrapper
5.3.5. The "gscan" wrapper
5.3.6. The bytestring wrappers The "basic-bytestring" wrapper The "posn-bytestring" wrapper The "monad-bytestring" wrapper The "monadUserState-bytestring" wrapper
6. Invoking Alex

List of Figures

2.1. A simple Alex specification.