Previous: , Up: Macros   [Contents][Index]


7.3 Preprocessing

Generally, the FWEB preprocessor commands follow a syntax identical to their C/C++ counterparts. The one exception is the ‘@#line’ command. Whereas the C command takes a line number and file name as arguments, the FWEB command takes no arguments; its expansion automatically inserts the current line number and file name. This command should be necessary only in rare circumstances. One of those involves situations in which an FWEB macro expands to more than one output line; see Debugging with macros.

The FWEB preprocessor commands may appear in either the definition or the code parts. But BEWARE: No matter where they appear, they are expanded during INPUT, not output. (This is probably a design flaw.) For more discussion, see FWEB macros.

The syntax of each command is as follows:

@#line

— Insert a #line command.

@#define identifier

— Define an FWEB macro; equivalent to ‘@m’.

@#undef identifier

— Undefine an FWEB macro.

@#ifdef identifier

— Is FWEB macro defined? Equivalent to ‘@#if defined identifier.

@#ifndef identifier

— Is FWEB macro not defined? Equivalent to ‘@#if !defined identifier.

@#if expression
@#elif expression
@#else
@#endif

In the ‘@#if’ statement, the expression may contain FWEB macros, but must ultimately evaluate to a number. If that number is zero, the expression is false; otherwise, it is true.

The expression following constructions such as ‘@#if’ is evaluated by a built-in expression evaluator that can also be used for other purposes, such as in macro expansion. Its behavior is again motivated by expression evaluation in ANSI C; it is not quite as general, but should be more than adequate. (One design flaw that will be fixed someday is that the order of expression evaluation is not necessarily left-to-right, as it is in C.) It supports both integer and floating-point arithmetic (with type promotion from integer to floating-point if necessary), and the ANSI defined operator. Operators with the highest precedence (see table below) are evaluated first; as usual, parentheses override the natural order of evaluation. The unary operator defined has the highest precedence; all the other unary operators have the next highest (and equal) precedence; then come the binary operators. When the operator exists in C, the action taken by FWEB is precisely that that the C compiler would take. Arithmetic is done in either long or double variables, as implemented by the C compiler that compiled FTANGLE. (This was the easy choice, not necessarily the most desirable one.)

The operators, listed from highest precedence to lowest, are as follows


Previous: , Up: Macros   [Contents][Index]