%{ /* 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 outfile to translate the text of infile and * save it to outfile. chef "bork"/{NW} ECHO; "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"); } "ew" { BEGIN INW; printf("oo"); } "e"/{NW} { BEGIN INW; printf("e-a"); } "e" { BEGIN INW; printf("i"); } "E" { BEGIN INW; printf("I"); } "f" { BEGIN INW; printf("ff"); } "ir" { BEGIN INW; printf("ur"); } "i" { BEGIN INW; printf(i_seen ? "i" : "ee"); } "ow" { BEGIN INW; printf("oo"); } "o" { BEGIN INW; printf("oo"); } "O" { BEGIN INW; printf("Oo"); } "o" { BEGIN INW; printf("u"); } "the" { BEGIN INW; printf("zee"); } "The" { BEGIN INW; printf("Zee"); } "th"/{NW} { BEGIN INW; printf("t"); } "tion" { BEGIN INW; printf("shun"); } "u" { BEGIN INW; printf("oo"); } "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; }