%{ /* anything between %{ and %} is copied directly into lex.yy.c */ /*#include only if yacc is used */ int yylval; %} /* definitions */ ws [ \n\t]* %% {ws} {} a {yylval = 1; printf("in rule1\n ");return('X');} b {yylval = 2; printf("in rule2\n"); return('Y');} %% /* 2nd set of %%s must appear IMMEDIATELY following end of pattern */ /* anything following %% (functions) are copied into lex.yy.c */ /* yywrap must be defined. says what to do at end of input */ int yywrap () { printf("done\n"); }