# BNF Converter

Markus Forsberg and Aarne Ranta

# OCaml Mode

## Requirements

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

- The Objective Caml system (includes lexer and parser generators `ocamllex` and `ocamlyacc)`
- LaTeX: A document preparation system

## Running the BNF Converter in OCaml mode

Example file JavaletteLight.cf.

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 JavaletteLight.cf
    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}@cs.chalmers.se.

    Reading grammar from JavaletteLight.cf
    21 rules accepted

    writing file AbsJavaletteLight.ml
    writing file LexJavaletteLight.mll
    writing file ParJavaletteLight.mly
    writing file DocJavaletteLight.tex
    writing file SkelJavaletteLight.ml
    writing file PrintJavaletteLight.ml
    writing file ShowJavaletteLight.ml
    writing file TestJavaletteLight.ml
    writing file BNFC_Util.ml
    Done!

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 JavaletteLight.cf`.

When you have produced the makefile, you can:

- type `make` to compile the parser, the lexer, the documentation and a test program.

You can now test to parse a Javalette file:

    $ ./TestJavaletteLight koe.jll
    [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 `koe.jll`.