Added 'C_C++/bison/string.y'
This commit is contained in:
25
C_C++/bison/string.y
Normal file
25
C_C++/bison/string.y
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* @BAKE
|
||||||
|
bison -o string.tab.c $@
|
||||||
|
g++ string.tab.c -o string
|
||||||
|
./string
|
||||||
|
@STOP
|
||||||
|
*/
|
||||||
|
%code requires {
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
void yyerror(...) { ; }
|
||||||
|
}
|
||||||
|
%union {
|
||||||
|
std::string * strval;
|
||||||
|
}
|
||||||
|
%{
|
||||||
|
int yylex() {
|
||||||
|
yylval.strval = new std::string("There are only two hard problems in CS: cache invalidation, nameing things, and off-by-one errors.");
|
||||||
|
return STRING;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
%token STRING
|
||||||
|
%%
|
||||||
|
string: STRING { std::cout << *(yylval.strval) << std::endl; }
|
||||||
|
%%
|
||||||
|
signed main() { yyparse(); }
|
Reference in New Issue
Block a user