Next: , Previous: , Up: FWEB macros   [Contents][Index]


7.2.2 Special tokens

The following special tokens may be used in the text of FWEB macro definitions:

7.2.2.1 ANSI C-compatible tokens

 ##          — Paste tokens on either side to form a new identifier.
 #parameter  — Convert parameter to string (without expansion).

For example,

@m FORTRAN(type, name) type _##name()
@m TRACE(where) puts("At " #where)
@a
FORTRAN(int, fcalc); // Expands to ‘int _fcalc();
TRACE(predictor); // Expands to ‘puts("At " "predictor");

7.2.2.2 Extensions to ANSI C macro syntax

The most frequently used extensions are the following ones associated with variable arguments: ‘#0’, ‘#n’, and ‘#.’. FORTRAN-77 users should also employ ‘#:0’ to allow symbolic rather than numeric statement labels. Try not to use the other extensions; they are experimental, complicated, and unlikely to work in all situations.

In the following list, the forms ‘#{n}’ and ‘#[n]’ may not work correctly in complicated situations. This is a design deficiency that may be corrected someday.

#*param

Like ‘#parameter’, but pass a quoted string through unchanged.

#!param

Don’t expand argument.

#'param

Convert parameter to a single-quoted string (no expansion).

#"param

Convert parameter to a double-quoted string (no expansion).

#0

Number of variable arguments.

#n

n-th variable argument, counting from 1.

#{0}

Like ‘#0’, but the argument may be a macro expression known at run time.

#{n}

Like ‘#n’, but the argument may be a macro expression.

#[0]

The total number of arguments (fixed + variable). (The argument inside the brackets may be a macro expression.)

#[n]

The nth argument (including the fixed ones), counting from 1. (The argument inside the brackets may be a macro expressions.

#.

Comma-separated list of all variable arguments.

#:0

Unique statement number (expanded in phase 1).

#:nnn

Unique statement number for each invocation of this macro (expanded in phase 2).

#<

Begin a module name.

#,

Internal comma; doesn’t delimit macro argument.

A few examples of the more important of these tokens are as follows:

@c
@m FPRINTF(fmt,...) fprintf(fp,fmt,#.) 
        // Use the whole list of variable args.
@m B(...) printf("There were %i arguments\n", #0) 
        // Use the number of var args.

@n
@
@m DONE #:0 // Symbolic statement label in FORTRAN.
@a
        goto DONE
        ...
DONE:
        call endup

Next: , Previous: , Up: FWEB macros   [Contents][Index]