yacc2latex

Yacc2latex generates human-readable EBNF grammars from yacc files. Output format is in Latex and fairly customizable.

Distribution

yacc2latex is available under LGLP licence

Dowload

How to install

Short Manual

Goal

As a language designer, I often faced the problem of writing and maintaining a reference (readable) grammar of my language. This is particularly annoying since the reference grammar actually exists as a yacc (or ocamlyacc) file, so why not use a “compiler” that will derived automaticaly the reference grammar from the yacc file ?

Deriving a readable, and reasonably compact, grammar from yacc is not so easy: basically it means discovering the EBNF grammar the designer had in mind when he wrote the yacc.

I found on the internet a nice tool form Kris Van Hees, y2l, but unfortunately relatively old, writen in AWK, and suffering limitations. In particular it was not possible to use it with mly file (ocamlyacc).

I started to write, around 2011, my own yacc to latex “compiler” for writing the reference manual of lab’s languages (Lustre and Lutin). The tool is is now fairly tested and stable, and I decided to make it available (through the LGPL licence), hope it may be helpfull for some people.

The main characteristics of yacc2latex are:

  • It integrates a yacc parser, made from scratch, that is (intended to be) completely agnostic to the embedded programming language, in particular it was made to support mly files (ocamlyacc sources). Indeed, classical C/C++ yacc should also work.
  • It integrates stategies to found EBNF patterns in the yacc (lists, factorization etc.)
  • For advanced use, it provides pragmas to give directives to the translation, in particular a huge grammar can be organized into “sections”.
  • The generated Latex code is parametric: is is possible to change the look of the document by re-defining a set of latex commands.

Example

As an example of what yacc2latex can do, here is the reference manual of Lutin, obtained from the ocamlyacc of Lutin.