1 /* Scanner for "C" assignment statements... sort of. */ 2 /* Compile: reflex --flex --bison-bridge --header-file flexexample4.l */ 3 /* Compile: bison -d -y flexexample4.y */ 4 /* Example taken from Flex documentation A.2 */ 5 /* Bison bridge passes yylval to yylex (which limits yylval's scope to the rule actions) */ 6 /* Note: yylval is no longer a pointer in reentrant/bison-bridge lexer specifications but a reference for convenience */ 7 8 %top{ 9 #include "y.tab.h" /* Generated by bison. */ 10 #define YY_EXTERN_C extern "C" /* this is needed for yylex C linkage when compiling y.tab.c in C */ 11 } 12 13 %option bison-bridge noyywrap header-file 14 15 %% 16 17 [[:digit:]]+ { yylval.num = atoi(yytext); return NUMBER; } 18 [[:alnum:]]+ { yylval.str = strdup(yytext); return STRING; } 19 "="|";" { return yytext[0]; } 20 .|\n {} 21 22 %% 23