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

3.4.1 Data Types of Semantic Values

In a simple program it may be sufficient to use the same data type for the semantic values of all language constructs. This was true in the RPN and infix calculator examples (see section Reverse Polish Notation Calculator).

Bison normally uses the type int for semantic values if your program uses the same data type for all language constructs. To specify some other type, define the %define variable api.value.type like this:

%define api.value.type {double}


%define api.value.type {struct semantic_type}

The value of api.value.type should be a type name that does not contain parentheses or square brackets.

Alternatively, instead of relying of Bison’s %define support, you may rely on the C/C++ preprocessor and define YYSTYPE as a macro, like this:

#define YYSTYPE double

This macro definition must go in the prologue of the grammar file (see section Outline of a Bison Grammar). If compatibility with POSIX Yacc matters to you, use this. Note however that Bison cannot know YYSTYPE’s value, not even whether it is defined, so there are services it cannot provide. Besides this works only for languages that have a preprocessor.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

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