3.1 Grammars and entries
The Camlp4 library provides a module ``Grammar'' and a syntax
extension file ``pa_extend.cmo'' to program grammars. All
details on modules, types and functions are described
chapter 6.
A grammar can be created using the function
``Grammar.create''. It takes a lexer as parameter. A good
candidate it the function ``Plexer.make'' but the user can
creates its own lexer, providing that it is of type
``Token.lexer''.
A grammar holds entries. An entry can be created using the function
``Grammar.Entry.create''. The first parameter is the grammar,
the second one is a string used to name the entry in error messages
and in entries dump. Entries are created empty, i.e. raising
``Stream.Error'' when called. An entry is composed of entry
precedence levels, the first one being the least precedent and the
last one the most.
Lastly, a stream can be parsed by en entry using the function
``Grammar.Entry.parse''. In case of syntax error, the
exception ``Stream.Error'' is raised, encapsulated by
the exception ``Stdpp.Exc_located'', giving the location
of the error.