Instantly share code, notes, and snippets.

What would you like to do?
Using std::variant as YYSTYPE/yylval in gnu bison for C++
#include <string>
#include <variant>
typedef std::variant<std::string, double> value_t;
#define YYSTYPE value_t
extern YYSTYPE yylval;
int yylex();
void yyerror(char const *s);
int main();
%token FOO
FOO { $$ = $1; }
int yylex()
yylval = std::string("hello");
return FOO;
void yyerror(char const *s)
int main()
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment