Camlp4 - Tutorial
version 3.07
Daniel de Rauglaudre
30 September 2003
Copyright © 2002 Institut National de Recherche en Informatique et Automatique
Introduction
Extending the syntax of OCaml
Using Camlp4 as a command and in the toplevel
Linking applications using Camlp4 libraries
Differences in parsing behavior
Streams and parsers
Streams
Parsers
Grammars in Camlp4
Grammar, entries: an example
Remark about the lexer
Labelled levels and associativity
Extending a level
Insert a level
Infix operator
Attributed grammars
Source location
Meta symbols: lists, options, levels
Local and global entries
Deleting a rule
Parsed language
Functorial interface
Writing a lexer
Grammar for OCaml syntax
Quotations
OCaml syntax extensions
Camlp4 quotation system
Example: defining constants
Quotations and the compiler
Pretty printing the result
Quotations returning syntax trees
Example: lambda terms
Antiquotations
Locations in antiquotations
Example: lambda terms, finished
Conclusion
The revised syntax
Practical points
Phrases
Imperative constructions
Tuples and lists
Irrefutable patterns
Constructions with matching
Mutables and assignment
Types
Modules
Classes and objects
Miscellaneous
Streams and parsers
OCaml syntax trees
Antiquotations
Antiquotations labels
Description
Extending the syntax of OCaml
Introduction
Example: ``repeat until'' like in Pascal
Example: a constant
Example: a ``for'' loop like in C
Example: generating printers of types
The camlp4 commands
The load options
The other options
The predefined object files
Commands camlp4o and camlp4r
Toplevel
This document was translated from L
A
T
E
X by
H
E
V
E
A and H
A
C
H
A
.