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

8.5.3 The YYPRINT Macro

The %printer directive was introduced in Bison 1.50 (November 2002). Before then, YYPRINT provided a similar feature, but only for terminal symbols and only with the yacc.c skeleton.

Macro: YYPRINT (stream, token, value);

Deprecated, will be removed eventually.

If you define YYPRINT, it should take three arguments. The parser will pass a standard I/O stream, the numeric code for the token kind, and the token value (from yylval).

For yacc.c only. Obsoleted by %printer.

Here is an example of YYPRINT suitable for the multi-function calculator (see section Declarations for mfcalc):

  static void print_token_value (FILE *file, int type, YYSTYPE value);
  #define YYPRINT(File, Type, Value)            \
    print_token_value (File, Type, Value)

… %% … %% …

static void
print_token_value (FILE *file, yytoken_kind_t kind, YYSTYPE value)
  if (kind == VAR)
    fprintf (file, "%s", value.tptr->name);
  else if (kind == NUM)
    fprintf (file, "%d", value.val);

See section Enabling Debug Traces for mfcalc, for the proper use of %printer.