Ratfor

Last updated
Ratfor
Developer Brian Kernighan
First appeared1976 (1976)
Website sepwww.stanford.edu
Influenced by
Fortran, C

Ratfor (short for Rational Fortran) is a programming language implemented as a preprocessor for Fortran 66. It provides modern control structures, unavailable in Fortran 66, to replace GOTOs and statement numbers.

Contents

Features

Ratfor provides the following kinds of flow-control statements, described by Kernighan and Plauger as "shamelessly stolen from the language C, developed for the UNIX operating system by D.M. Ritchie" ("Software Tools", p. 318):

For example, the following code

if(a>b){max=a}else{max=b}

might be translated as

IF(.NOT.(A.GT.B))GOTO1MAX=AGOTO2    1CONTINUEMAX=B    2CONTINUE

The version of Ratfor in Software Tools is written in Ratfor, as are the sample programs, and inasmuch as its own translation to Fortran is available, it can be ported to any Fortran system. Ratfor source code file names end in .r or .rat.

History

Ratfor was designed and implemented by Brian Kernighan at Bell Telephone Laboratories in 1974, and described in SoftwarePractice & Experience in 1975. It was used in the book "Software Tools" (Kernighan and Plauger, 1976).

In 1977, at Purdue University, an improved version of the Ratfor preprocessor was written. It was called Mouse4, as it was smaller and faster than Ratfor. A published document by Dr. Douglas Comer, professor at Purdue, concluded "contrary to the evidence exhibited by the designer of Ratfor, sequential search is often inadequate for production software. Furthermore, in the case of lexical analysis, well-known techniques do seem to offer efficiency while retaining the simplicity, ease of coding and modularity of ad hoc methods." (CSD-TR236).

In comparison to the Ratfor preprocessor on a program of 3000 source lines running on a CDC 6500 system took 185.470 CPU seconds. That was cut by 50% when binary search was used in the Ratfor code. Rewriting the ad hoc lexical scanner using a standard method based on finite automata reduced run time to 12.723 seconds.

With the availability of Fortran 77, a successor named Ratfiv (Ratfor=rat4 => rat5=Ratfiv) could, with an option /f77, output a more readable Fortran 77 code:

IF(A.GT.B)THENMAX=AELSEMAX=BENDIF

Initial Ratfor source code was ported to C in 1985 [1] and improved to produce Fortran 77 code too. [2] A git tree has been set in 2010 in order to revive ratfor . [3] Although the GNU C compiler had the ability to directly compile a Ratfor file (.r) without keeping a useless intermediate Fortran code (.f) (gcc foo.r), this functionality was lost in version 4 during the move in 2005 from f77 to GNU Fortran. [4]

The original source was available in .deb and .rpm forms at its original site, mirror.corbina.net/mandriva/, and its archive, www.dgate.org/ratfor/ are gone as of April, 2024.

Ratfiv

Ratfiv is an enhanced version of the Ratfor programming language, a preprocessor for Fortran designed to give it C-like capabilities. Fortran was widely used for scientific programming but had very basic control-flow primitives ("do" and "goto") and no "macro" facility which limited its expressiveness.

The name of the language is a pun (Ratfor (RATional FORtran) -> "Rat Four" -> "Rat Five" -> RatFiv).

Ratfiv was developed by Bill Wood at the Institute for Cancer Research, Philadelphia, PA in the early 1980s and released on several DECUS (Digital Equipment Users Group) SIG (Special Interest Group) tapes. It is based on the original Ratfor by B. Kernighan and P. J. Plauger, with rewrites and enhancements by David Hanson and friends (U. of Arizona), Joe Sventek and Debbie Scherrer (Lawrence Berkeley National Laboratory).

Ratfiv V2.1 was distributed on the DECUS RSX82a SIG tape. [5]

See also

Related Research Articles

<span class="mw-page-title-main">Brian Kernighan</span> Canadian computer scientist

Brian Wilson Kernighan is a Canadian computer scientist. He worked at Bell Labs and contributed to the development of Unix alongside Unix creators Ken Thompson and Dennis Ritchie. Kernighan's name became widely known through co-authorship of the first book on the C programming language with Dennis Ritchie. Kernighan affirmed that he had no part in the design of the C language.

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

<span class="mw-page-title-main">Fortran</span> General-purpose programming language

Fortran is a third generation, compiled, imperative programming language that is especially suited to numeric computation and scientific computing.

<span class="mw-page-title-main">GNU Compiler Collection</span> Free and open-source compiler for various programming languages

The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. The Free Software Foundation (FSF) distributes GCC as free software under the GNU General Public License. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and the Linux kernel. With roughly 15 million lines of code in 2019, GCC is one of the biggest free programs in existence. It has played an important role in the growth of free software, as both a tool and an example.

A "Hello, World!" program is generally a simple computer program which outputs to the screen a message similar to "Hello, World!" while ignoring any user input. A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. A "Hello, World!" program is often the first written by a student of a new programming language, but such a program can also be used as a sanity check to ensure that the computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.

troff, short for "typesetter roff", is the major component of a document processing system developed by Bell Labs for the Unix operating system. troff and the related nroff were both developed from the original roff.

Yacc is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a lookahead left-to-right rightmost derivation (LALR) parser generator, generating a LALR parser based on a formal grammar, written in a notation similar to Backus–Naur form (BNF). Yacc is supplied as a standard utility on BSD and AT&T Unix. GNU-based Linux distributions include Bison, a forward-compatible Yacc replacement.

In computer science, a preprocessor is a program that processes its input data to produce output that is used as input in another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The amount and kind of processing done depends on the nature of the preprocessor; some preprocessors are only capable of performing relatively simple textual substitutions and macro expansions, while others have the power of full-fledged programming languages.

In computer programming, indentation style is a convention, a.k.a. style, governing the indentation of blocks of source code that is generally intended to convey structure.

A programming tool or software development tool is a computer program that software developers use to create, debug, maintain, or otherwise support other programs and applications. The term usually refers to relatively simple programs, that can be combined to accomplish a task, much as one might use multiple hands to fix a physical object. The most basic tools are a source code editor and a compiler or interpreter, which are used ubiquitously and continuously. Other tools are used more or less depending on the language, development methodology, and individual engineer, often used for a discrete task, like a debugger or profiler. Tools may be discrete programs, executed separately – often from the command line – or may be parts of a single large program, called an integrated development environment (IDE). In many cases, particularly for simpler use, simple ad hoc techniques are used instead of a tool, such as print debugging instead of using a debugger, manual timing instead of a profiler, or tracking bugs in a text file or spreadsheet instead of a bug tracking system.

Flex is a free and open-source software alternative to lex. It is a computer program that generates lexical analyzers . It is frequently used as the lex implementation together with Berkeley Yacc parser generator on BSD-derived operating systems, or together with GNU bison in *BSD ports and in Linux distributions. Unlike Bison, flex is not part of the GNU Project and is not released under the GNU General Public License, although a manual for Flex was produced and published by the Free Software Foundation.

<span class="mw-page-title-main">IRAF</span> Software collection for astronomical data reduction and data analysis

IRAF is a collection of software written at the National Optical Astronomy Observatory (NOAO) geared towards the reduction of astronomical images and spectra in pixel array form. This is primarily data taken from imaging array detectors such as CCDs. It is available for all major operating systems for mainframes and desktop computers. IRAF was designed cross-platform, supporting VMS and UNIX-like operating systems. Use on Microsoft Windows was made possible by Cygwin in earlier versions, and can be today done with the Windows Subsystem for Linux. Today, it is primarily used on macOS and Linux.

<span class="mw-page-title-main">README</span> Software information file

In software development, a README file contains information about the other files in a directory or archive of computer software. A form of documentation, it is usually a simple plain text file called README, Read Me, READ.ME, README.TXT, README.md, or README.1ST.

The GNU toolchain is a broad collection of programming tools produced by the GNU Project. These tools form a toolchain used for developing software applications and operating systems.

m4 is a general-purpose macro processor included in most Unix-like operating systems, and is a component of the POSIX standard.

<i>The Elements of Programming Style</i> 1978 book by Brian W. Kernighan and P. J. Plauger

The Elements of Programming Style, by Brian W. Kernighan and P. J. Plauger, is a study of programming style, advocating the notion that computer programs should be written not only to satisfy the compiler or personal programming "style", but also for "readability" by humans, specifically software maintenance engineers, programmers and technical writers. It was originally published in 1974.

<span class="mw-page-title-main">Watcom C/C++</span>

Watcom C/C++ is an integrated development environment (IDE) product from Watcom International Corporation for the C, C++, and Fortran programming languages. Watcom C/C++ was a commercial product until it was discontinued, then released under the Sybase Open Watcom Public License as Open Watcom C/C++. It features tools for developing and debugging code for DOS, OS/2, and Windows, Linux operating systems, which are based upon 16-bit x86, 32-bit IA-32, or 64-bit x86-64 compatible processors.

<span class="mw-page-title-main">Goto</span> One-way control statement in computer programming

Goto is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control. The jumped-to locations are usually identified using labels, though some languages use line numbers. At the machine code level, a goto is a form of branch or jump statement, in some cases combined with a stack adjustment. Many languages support the goto statement, and many do not.

Mingw-w64 is a free and open source software development environment to create (cross-compile) Microsoft Windows PE applications. It was forked in 2005–2010 from MinGW.

<span class="mw-page-title-main">Software Tools Users Group</span>

The Software Tools Users Group (STUG) was a technical organization started in 1976, in parallel with Usenix. The STUG goal was to develop a powerful and portable Unix-like system that could be implemented on top of virtually any operating system, providing the capabilities and features of Unix in a non-proprietary system. With its focus on building clean, portable, reusable code shared amongst multiple applications and runnable on any operating system, the Software Tools movement reestablished the tradition of open source and the concepts of empowering users to define, develop, control, and freely distribute their computing environment.

References

  1. "Ratfor implementation in C (1985)".
  2. "Ratfor77".
  3. "Ratfor Git Revived".
  4. "gcc lost the ratfor preprocessor".
  5. Ratfiv V2.1 archive