Make yylex return symbol_type instead of int
<p>I'm trying to return symbol objects from yylex, as is shown in this documentation <a href="http://www.gnu.org/software/bison/manual/html_node/Complete-Symbols.html" rel="nofollow">http://www.gnu.org/software/bison/manual/html_node/Complete-Symbols.html</a></p>

<p>However, when I compile, I find that <code>return yy::parser::make_PLUS();</code> gets put into <code>int yyFlexLexer::yylex()</code>, so I get this error message (and many similar ones form other rules):</p>

<pre><code>lexer.ll:22:10: error: no viable conversion from 'parser::symbol_type' (aka 'basic_symbol&lt;yy::parser::by_type&gt;') to 'int'
{ return yy::parser::make_PLUS(); }
</code></pre>

<p>What is the correct way to fix this?</p>

<p>lexer.ll</p>

<pre><code>%{
#include "ASTNode.hpp"

// why isn't this in parser.tab.hh?
# ifndef YY_NULLPTR
#  if defined __cplusplus &amp;&amp; 201103L &lt;= __cplusplus
#   define YY_NULLPTR nullptr
#  else
#   define YY_NULLPTR 0
#  endif
# endif

#include "parser.tab.hh"

#define yyterminate() return yy::parser::make_END()
%}

%option nodefault c++ noyywrap

%%
"+"            { return yy::parser::make_PLUS(); }
"-"            { return yy::parser::make_MINUS(); }
... more rules ...
%%
</code></pre>

<p>parser.yy</p>

<pre><code>%{
#include "AstNode.hpp"
#include ...

static int yylex(yy::parser::semantic_type *arg);
%}

%skeleton "lalr1.cc"

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

%token          END 0
%token          PLUS
%token          MINUS
%token ... many tokens ...
%type   &lt;ASTNode *&gt; S statement_list ...

%%

S:      statement_list
        { $$ = g_ast = (StatementList *)$1; }
    ;

... more rules ...

%%

static int yylex(yy::parser::semantic_type *arg) {
    (void)arg;
    static FlexLexer *flexLexer = new yyFlexLexer();
    return flexLexer-&gt;yylex();
}

void yy::parser::error(const std::string &amp;msg) {
    std::cout &lt;&lt; msg &lt;&lt; std::endl;
    exit(1);
}
</code></pre>