/*** An example based on the source code of OCaml 3.11.0, bytecomp/symtable.ml ***/
/*** The function ReadSec passes to C1 three closures for reading/closing a file.
 *** C1 then uses the closures to read/close the file.
 ***/

%BEGING
S -> ReadSec C1.
C1 rstring rstruct clreader -> rstruct (rstring (Loop rstring rstruct clreader)).
Loop rstring rstruct clreader -> br (DLLinit rstring rstruct clreader) (Loop rstring rstruct clreader).
DLLinit rstring rstruct clreader -> rstring (rstruct (clreader end)).
/*** readsec ***/
ReadSec k -> br (k Nop Nop Nop) (Newr (ReadSec2 k)).
ReadSec2 k x -> ReadToc x (ReadSec3 x k).
ReadSec3 x k -> k (Rsecstr x) (Rsecstruct x) (Close x).
Nop k -> k.
/*** readtoc ***/
ReadToc x k -> SeekIn x (InputBinary x (ReallyInput x (SeekIn x (ReadTocLoop x k)))).
ReadTocLoop x k -> br k (ReallyInput x (InputBinary x (ReadTocLoop x k))).
/*** Rsecstr **/
Rsecstr x k -> SeekSec x (ReallyInput x k).
/*** Rsecstruct **/
Rsecstruct x k -> SeekSec x (InputValue x k).
/*** SeekSec ***/
SeekSec x k -> SeekSub x k.
SeekSub x k -> br (SeekIn x k) (SeekSub x (SeekIn x k)). 
SeekIn x k -> Read x k.
ReallyInput x k -> Read x k.
InputBinary x k -> Read x k.
InputValue x k -> Read x k.
/*** common definitions for read-only files ***/
I x y -> x y.
K x y -> y.
Newr k -> br (newr (k I)) (k K).
Close x k -> x close k.
Read x k -> x read k.
/** #rule: 23, rule size: 110 **/
%ENDG

%BEGINA
q0 br -> q0 q0.
qr br -> qr qr.
q0 newr -> qr.
qr newr -> top.
qr read -> qr.
qr close -> qc.
qc end ->.
q0 end ->.
%ENDA
