/* File: woof7.l This version splits up the program into 3 pieces: woof7.y, parser.h and parser.c. Compile using: % flex woof7.l % gcc -c lex.yy.c % gcc -c parser.c % gcc parser.o lex.yy.o */ %option noyywrap %{ #include #include "parser.h" extern YYSTYPE yylval ; %} %% <> { sprintf(yylval, "\nWoof! are we done talking?\n"); return END; } treat { sprintf(yylval, "\n!!!%s!!! Woof! yummy!\n", yytext); return HEARD; } walk { sprintf(yylval, "\n!!!%s!!! Woof! where's the leash?\n", yytext); return HEARD; } dinner { sprintf(yylval, "\n!!!%s!!! Woof! I'm hungry!\n", yytext); return HEARD; } good\ dog { sprintf(yylval, "\n!!!%s!!! Woof! talking about me!\n", yytext); return HEARD; } [@#%$^&] { return yytext[0] ; } \n { yylval[0] = '\0' ; return NEWLINE; } . { yylval[0] = '\0' ; return IGNORED; } %%