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

8.4.3 The YYPRINT Macro

Before %printer support, semantic values could be displayed using the YYPRINT macro, which works only for terminal symbols and only with the yacc.c skeleton.

Macro: YYPRINT (stream, token, value);

If you define YYPRINT, it should take three arguments. The parser will pass a standard I/O stream, the numeric code for the token type, 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 Declarations for mfcalc):

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

… %% … %% …

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