Ocamllex Tutorial

Ocamllex Adaptation: SooHyoung Oh

This is a tutorial on how to use ocamllex which is distributed with Ocaml language.

This document borrowed lots of part from flex manual.

Please mail all comments and suggestions to

This tutorial is work-in-progress. The latest version can be found at http://pllab.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamllex-tutorial/index.html.

The companion tutorial for ocamlyacc is available at http://pllab.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamlyacc-tutorial/index.html.

You can find the source of this document in ocamllex-tutorial-src.tar.gz. For printing, pdf (A4 size) is presented, and there is html (tar.gz).

You can download the source of examples used in this document from ocamllex-examples.tar.gz.

Last updated: 2004-11-16

Table of Contents
1. Introduction
2. Some simple examples
3. Format of the input file
4. Patterns
5. How the input is matched
6. Actions
6.1. Position
7. The generated scanner
8. Start conditions
9. Interfacing with ocamlyacc
10. Options
11. Usage Tips
11.1. Keyword Hashtable
11.2. Nested Comments
12. Examples
12.1. Translate
12.2. Word Count
12.3. Toy Language
13. License
13.1. License in flex manual
13.2. Ocamllex Adaptation Copyright and Permissions Notice