%{
/* chef.x - convert English on stdin to Mock Swedish on stdout
 *
 * The WC definition matches any word character, and the NW definition matches
 * any non-word character.  Two start conditions are maintained: INW (in word)
 * and NIW (not in word).  The first rule passes TeX commands without change.
 *
 * HOW TO COMPILE
 *
 * 1. Save this file as chef.l
 * 2. lex chef.l   This will produce a file called lex.yy.c
 * 3.  cc -o chef lex.yy.c -ll  This will produce a file called chef.
 * 4.  chef <infile >outfile to translate the text of infile and 
 * save it to outfile.  chef <infile |more to look at the translated
 * infile without saving.  chef by itself to translate what you 
 * type in.  
 * 
 * HISTORY
 *
 * Apr 15, 1992; John Hagerman: Created.
 * Dec 10, 1994; Marius Watz: Compilation omments added for easier 
 * distribution.
 */

static int i_seen = 0;
%}

WC             [A-Za-z']
NW             [^A-Za-z']

%start         INW NIW

%%

\\[ \n]+      ECHO;

{NW}           { BEGIN NIW; i_seen = 0; ECHO; }
","$           { BEGIN NIW; i_seen = 0; printf(".\nBork Bork Bork!"); }

<NIW>"bork"/{NW} ECHO;
<NIW>"Bork"/{NW} ECHO;

"an"           { BEGIN INW; printf("un"); }
"An"           { BEGIN INW; printf("Un"); }
"au"           { BEGIN INW; printf("oo"); }
"Au"           { BEGIN INW; printf("Oo"); }
"a"/{WC}       { BEGIN INW; printf("e"); }
"A"/{WC}       { BEGIN INW; printf("E"); }
"en"/{NW}      { BEGIN INW; printf("ee"); }
<INW>"ew"      { BEGIN INW; printf("oo"); }
<INW>"e"/{NW}  { BEGIN INW; printf("e-a"); }
<NIW>"e"       { BEGIN INW; printf("i"); }
<NIW>"E"       { BEGIN INW; printf("I"); }
<INW>"f"       { BEGIN INW; printf("ff"); }
<INW>"ir"      { BEGIN INW; printf("ur"); }
<INW>"i"       { BEGIN INW; printf(i_seen ? "i" : "ee"); }
<INW>"ow"      { BEGIN INW; printf("oo"); }
<NIW>"o"       { BEGIN INW; printf("oo"); }
<NIW>"O"       { BEGIN INW; printf("Oo"); }
<INW>"o"       { BEGIN INW; printf("u"); }
"the"          { BEGIN INW; printf("zee"); }
"The"          { BEGIN INW; printf("Zee"); }
"th"/{NW}      { BEGIN INW; printf("t"); }
<INW>"tion"    { BEGIN INW; printf("shun"); }
<INW>"u"       { BEGIN INW; printf("oo"); }
<INW>"U"       { BEGIN INW; printf("Oo"); }
"v"            { BEGIN INW; printf("f"); }
"V"            { BEGIN INW; printf("F"); }
"w"            { BEGIN INW; printf("v"); }
"W"            { BEGIN INW; printf("V"); }

.              { BEGIN INW; ECHO; }