Created
May 18, 2018 09:50
-
-
Save blippy/4c476ac18cf1e0a1548680db36e552d6 to your computer and use it in GitHub Desktop.
Using std::variant as YYSTYPE/yylval in gnu bison for C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#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