Search code examples
c++bison

using enum as semantic type in Bison C++


How can I use an enum as type as shown below

%type <order_direction> ordering_direction opt_ordering_direction

when i have defined order_direction in a separate header file as

enum enum_order : int { ORDER_NOT_RELEVANT = 1, ORDER_ASC, ORDER_DESC };
enum_order order_direction;

which i include in the Bison file? When i try to link the object files i get this error:

error: ‘order_direction’ is not a type
 5091 |       basic_symbol (typename Base::kind_type t, order_direction&& v, location_type&& l)

I also use the following definitions in my .y file

%define api.token.constructor
%define api.value.type variant
%define parse.assert

Solution

  • The problem is that enum_direction is an enumerator and not an enumaration type. This means enum_direction cannot be used as a type.

    To solve this, you must use a type where a type is required. This means you can use enum_order as the type of the function parameter instead of enum_direction( as the former is a type).