Go to the first, previous, next, last section, table of contents.


RATFOR

"RATFOR" stands for "RATIONAL FORTRAN". It endows FORTRAN with a C-like syntax. Certain loop and other constructions (such as `switch' or `i++') that are not allowed in FORTRAN are allowed in RATFOR; FWEB translates those into proper FORTRAN.

Although RATFOR is a definite improvement over FORTRAN, it certainly does not have the power of C (e.g., elegant pointer notation) or C++ (e.g., classes). Many advantages accrue by taking the time to learn C. RATFOR offers a gentle transition. (It is not supported very actively any more.)

RATFOR syntax

A sample RATFOR program is

@r
@
@a
program main
{
integer k;
real fcn, x;

for(k=0; k<10; k++)
        {
        x = fcn(k);

        if(x < 0.0)
                {
                x = 0.0;
                break;
                }
        }
}

The concluding brace of a function is translated into an END statement. Note the use of semicolons to terminate statements, braces to delimit compound statements, `<' instead of `.LT.', the C-like for construction, and the `k++' expression.

Constructions like `k++' or `k -= l + 1' must be used with great care. They translate to statements involving `=' signs, so they can be used only where simple statements are allowed, not essentially anywhere as in C (for example, they cannot be used as function arguments).

RATFOR commands

RATFOR--77 commands

 break; // Used with |case| or to break out of loops, as in C.
 case i: // Used with |switch|.
 default: // Used with |case|, as in C.
 do ...; {...} // Note the semicolon (unnecessary if followed by a compound stmt).
 else {...} // Used after |if| as in C.
 for(a;b;c) {...} // As in C.
 if(condition) {...}
 next; // Equivalent to C's |continue| statement; go to bottom of loop.
 repeat {...} until(condition); // Equivalent to C's |do {...} while();|
 return expression; // As in C.
 switch(expression) {...} // As in C.
 while(condition) {...} // Like C's |while|.

Additional RATFOR--90 commands

 contains:
 interface name {...}
 interface operator(op) {...}
 interface assignment(assgnmnt) {...}
 module name {...}
 private:
 sequence:
 type name {...}
 where(expression) {...}

Caveats about RATFOR

The version of RATFOR built into FWEB differs slightly from its UNIX counterpart:

  1. Numeric statement labels must be followed by a colon; they should be first on their line. (Use symbolic statement labels instead; see the discussion of `#:0' in section Special tokens.)
  2. The quoting convention for characters and strings follows that of C: Single-quote single characters, double-quote strings.
  3. In a switch, cases fall through to the next case unless terminated by break (just as in C).
  4. The do statement must be terminated by a semicolon if followed by a simple statement. (It's unnecessary if followed by a left brace that begins a compound statement.)
  5. Use && and || for the logical AND and OR.
  6. Do not use an end statement at the very end of a program unit; it is added automatically by FWEB when the closing brace is sensed.


Go to the first, previous, next, last section, table of contents.