BNF Converter

Markus Forsberg and Aarne Ranta

OCaml Mode


You need the following programs installed on your system to be able to run BNF Converter in OCaml mode:

Running the BNF Converter in OCaml mode

Example file

Producing the output files without compiling them is done by typing bnfc -ocaml file.

If this is run on the example file, the output looks like this:

$ bnfc -ocaml 
The BNF Converter, 2.2
(c) Bjorn Bringert, Paul Callaghan, Markus Forsberg, Peter Gammie,
    Patrik Jansson, Antti-Juhani Kaijanaho, Michael Pellauer,
    and Aarne Ranta 2002 - 2004.
Free software under GNU General Public License (GPL).
Bug reports to {markus,aarne}

Reading grammar from
21 rules accepted

writing file
writing file LexJavaletteLight.mll
writing file ParJavaletteLight.mly
writing file DocJavaletteLight.tex
writing file
writing file
writing file
writing file
writing file

You could now compile LexJavaletteLight.mll, ParJavaletteLight.mly and DocJavaletteLight.tex by hand, using ocamllex, ocamlyacc and latex.

You can also produce a makefile, named Makefile, by typing bnfc -ocaml -m

When you have produced the makefile, you can:

You can now test to parse a Javalette file:

$ ./TestJavaletteLight
[Abstract syntax]

Fun (TInt, Ident "main", [SDecl (TInt, Ident "i"); SDecl (TDouble, Ident
"d"); SAss (Ident "i", EInt (0)); SAss (Ident "d", EDouble (1.)); SWhile
(ELt (EVar (Ident "i"), EInt (10)), [SAss (Ident "d", ETimes (EVar
(Ident "d"), EDouble (0.5))); SIncr (Ident "i")])])

[Linearized tree]

int main () {
  int i ;
  double d ;
  i = 0 ;
  d = 1. ;
  while (i < 10){
    d = d * 0.5 ;
    i ++ ;

To make this test yourself, just copy the linearization result into a file