manpagez: man pages & more
info bison
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4.5 Providing a Structured Semantic Value Type

Instead of %union, you can define and use your own union type YYSTYPE if your grammar contains at least one ‘<type>’ tag. For example, you can put the following into a header file ‘parser.h’:

union YYSTYPE {
  double val;
  symrec *tptr;

and then your grammar can use the following instead of %union:

#include "parser.h"
%define api.value.type {union YYSTYPE}
%type <val> expr
%token <tptr> ID

Actually, you may also provide a struct rather that a union, which may be handy if you want to track information for every symbol (such as preceding comments).

The type you provide may even be structured and include pointers, in which case the type tags you provide may be composite, with ‘.’ and ‘->’ operators.

This document was generated on December 1, 2013 using texi2html 5.0.

© 2000-2017
Individual documents may contain additional copyright information.