Reverse Literate Programming

Markus Knasmüller

Knuths Literate Programming system allows to design and describe a program hierarchically according to the method of stepwise refinement. The result is a program code which can be read sequentially like a book, section after section. This helps reading the printed source listing, but on-screen programs are read rather selectively like an encyclopedia. There the programmer wants a system which allows and possibly even encourages selective browsing. Zoom in at interesting points or jump to other locations according to control flow or other semantic relationships. This is the approach of hypertext. Here we demonstrate a solution, called Reverse Literate Programming, which combines the advantages of Knuths and of the hypertext approach. We implemented active text elements which made it possible to have the source code as a hyertext screen document. A special print command prints this document as a Literate Programming output, resulting in an essay, with documentation, pictures, and program code. The implementation was done in the Oberon system which offers powerful mechanisms for extending software in an object-oriented way.

The following table shows a sample source code, structured with fold elements. It is a small demonstration of the use of Reverse Literate Programming in a program that prints the famous Hello World greeting.

The left part of the table shows the source code, whereby all fold elements are expanded. It can be seen that there is a link between the call of the operation Out.String and the import of the module Out. The right part of the feature shows the wrapped comment of the Import Statement Section. Also the Output Procedure Section and the Main Section have a wrapped comment. The following shows the Literate Programming document which our system would generate by such an input.

1. Hello World program.

This is a small demonstration of the use of Reverse Literate Programming in a program that prints the famous Hello World greeting.

MODULE HelloWorld;
[Import Statement]
[Output Procedure]
END HelloWorld.

See also Sections 2, 3.

2. Import Statement.

The only imported module required is Out. Module Out provides a set of basic routines for formatted output of characters, numbers, and strings. It assumes a standard output stream to which the symbols are written.

[Import Statement] =

This code is used in Section 1.

3. Output Procedure.

This procedure, called Do, uses the operation Out.String to write the string "Hello World" to the standard output stream.

[Output Procedure] =
Out.String ("Hello World")

This code is used in Section 1.
See also Section 2.

  • Prototype available via ftp

    Publications about Reverse Literate Programming

  • Reverse Literate Programming - An Introduction