/
chef.l
62 lines (51 loc) · 1.9 KB
/
chef.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%{
/* 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.
*
* HISTORY
*
* Apr 15, 1992; John Hagerman: Created.
*/
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; }