Skip to content

Instantly share code, notes, and snippets.

@blippy
Created May 18, 2018 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blippy/4c476ac18cf1e0a1548680db36e552d6 to your computer and use it in GitHub Desktop.
Save blippy/4c476ac18cf1e0a1548680db36e552d6 to your computer and use it in GitHub Desktop.
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
%%
top:
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