]>
Commit | Line | Data |
---|---|---|
1 | %{ | |
2 | /* | |
3 | * Lex filter to transform plain English into Cockney English. | |
4 | * No racial or societal slurs are intended. For amusement only. | |
5 | * | |
6 | * Copyright 1986 by Daniel Klein. | |
7 | * | |
8 | * Reproduction permitted so long as this notice is retained. | |
9 | */ | |
10 | %} | |
11 | ||
12 | BW [ \t\n] | |
13 | SP [ \t]+ | |
14 | EW [ \t.,;!\?$] | |
15 | ||
16 | %Start junk | |
17 | ||
18 | %% | |
19 | <junk>. { srandom(time(0L)); unput(yytext[0]); BEGIN 0; } | |
20 | {BW}[Tt]he{EW} { ECHO; bloody(); } | |
21 | {BW}[Ss]teal{EW} { printf("%c%cick",yytext[0],yytext[1]-5); | |
22 | eos(); | |
23 | } | |
24 | {BW}[Ss]tole{EW} { printf("%c%cicked",yytext[0],yytext[1]-5); | |
25 | eos(); | |
26 | } | |
27 | {BW}tired pooped(); | |
28 | {BW}were{EW} | | |
29 | {BW}was{EW} { printf("%cwuz",yytext[0]); eos(); } | |
30 | [Hh]ello printf("'%cllo", caseify('u')); | |
31 | {BW}[Hh] printf("%c'",yytext[0]); | |
32 | {BW}[Yy]our{EW} { printf("%.2ser",yytext); eos(); } | |
33 | {BW}it{EW} { printf("%.2s'",yytext); eos(); } | |
34 | {BW}go{EW} { printf("%.2sow",yytext); eos(); } | |
35 | {BW}and{EW} { printf("%c'n'",yytext[0]); eos(); } | |
36 | {BW}my{EW} { printf("%.2se",yytext); eos(); } | |
37 | {BW}th(is|at){EW} { printf("%.5s", yytext); eos(); } | |
38 | {BW}[Ww]e{SP}went{EW} | | |
39 | {BW}[Ww]e{SP}had{EW} | | |
40 | {BW}[Ww]e{SP}did{EW} { printf("%.*s",yyleng-1,yytext); | |
41 | set_did(2); | |
42 | eos(); | |
43 | } | |
44 | {BW}I{SP}went{EW} | | |
45 | {BW}I{SP}had{EW} | | |
46 | {BW}I{SP}did{EW} { I(); | |
47 | printf(" did"); | |
48 | set_did(1); | |
49 | eos(); | |
50 | } | |
51 | {BW}I{EW} { I(); eos(); } | |
52 | ||
53 | [Yy]ou{SP}[^aeiouy] { printf("%c'", yytext[0]); plastc(); } | |
54 | [Ww]hat{SP}are{EW} { printf("%cotta", yytext[0]); eos(); } | |
55 | ||
56 | {BW}other | | |
57 | [MmNnRr]other printf("%cuvver",yytext[0]); | |
58 | [MmSs]outh printf("%cowf", yytext[0]); | |
59 | [cYy]outh printf("%coof", yytext[0]); | |
60 | [^o]uth printf("%.2sf",yytext); | |
61 | {BW}th[^e] | | |
62 | [AaEeIiOo]th[^em] { printf("%cf",yytext[0]); plastc(); } | |
63 | oothe | | |
64 | e[ei]the { printf("%c%cve", yytext[0], yytext[0]); } | |
65 | ooth | | |
66 | eeth { printf("%c%cf", yytext[0], yytext[0]); } | |
67 | [aei]the { printf("%cvv",yytext[0]); plastc(); } | |
68 | th putchar('v'); | |
69 | a[km]e{EW} { printf("i%ce",yytext[1]); eos(); } | |
70 | [^r][Oo]ld printf("%.2swld",yytext); | |
71 | [^AaEeIiOoUu][uo]nd[a-z] printf("%cunn%c",yytext[0],yytext[yyleng-1]); | |
72 | ing{EW} { printf("in'"); eos(); } | |
73 | [^dg]get+[^h] printf("%cge'%c",yytext[0],yytext[yyleng-1]); | |
74 | ail printf("aiw"); | |
75 | any printf("enny"); | |
76 | [rSs]ay{EW} { printf("%cigh",yytext[0]); eos(); } | |
77 | way printf("why"); | |
78 | [BbHh]it{EW} { printf("%ci'",yytext[0]); eos(); } | |
79 | ait{EW} { printf("ite"); eos(); } | |
80 | ime{EW} { printf("oime"); eos(); } | |
81 | [^e]ize[^n] printf("%coize%c",yytext[0],yytext[yyleng-1]); | |
82 | [^e]ight printf("%coit",*yytext); | |
83 | [a-z]"?" { *(yytext+1) = ','; | |
84 | printf("%s roit?",yytext); | |
85 | clear_did(); | |
86 | } | |
87 | [a-z]"." { printf("%c", yytext[0]); dintI(); } | |
88 | \n printf("\n"); | |
89 | ||
90 | %% | |
91 | ||
92 | eos() | |
93 | { | |
94 | if (yytext[yyleng-1] == '.') | |
95 | dintI(); | |
96 | else | |
97 | yyunput(yytext[yyleng-1], yytext); | |
98 | } | |
99 | ||
100 | plastc() | |
101 | { | |
102 | yyunput(yytext[yyleng-1], yytext); | |
103 | } | |
104 | ||
105 | main() | |
106 | { | |
107 | yylex(); | |
108 | } | |
109 | ||
110 | int yywrap() | |
111 | { | |
112 | return 1; | |
113 | } | |
114 | ||
115 | caseify(c) | |
116 | char c; | |
117 | { | |
118 | if (yytext[0] <= 'Z') | |
119 | return (c - ' '); | |
120 | else | |
121 | return (c); | |
122 | } | |
123 | ||
124 | ||
125 | I() | |
126 | { | |
127 | /* extern long random(); */ | |
128 | ||
129 | if (random() % 100 < 20) | |
130 | printf("%cOy",yytext[0]); | |
131 | else | |
132 | printf("%cI",yytext[0]); | |
133 | } | |
134 | ||
135 | static short b_count = 0; | |
136 | static short b_which = 0; | |
137 | ||
138 | bloody() | |
139 | { | |
140 | if (b_count++ % 2 == 0) { | |
141 | switch (b_which++ % 4) { | |
142 | case 0: printf("bloody "); break; | |
143 | case 1: printf("flinkin' "); break; | |
144 | case 2: printf("bleedin' "); break; | |
145 | case 3: printf("soddin' "); break; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | static short did = 0; | |
151 | ||
152 | set_did(val) | |
153 | { | |
154 | did = val; | |
155 | } | |
156 | ||
157 | clear_did() | |
158 | { | |
159 | did = 0; | |
160 | } | |
161 | ||
162 | dintI() | |
163 | { | |
164 | /* extern long random(); */ | |
165 | ||
166 | if ((did == 1) && (random() % 100 < 50)) | |
167 | printf(", didn'I?"); | |
168 | else if ((did == 2) && (random() % 100 < 50)) | |
169 | printf(", din't we?"); | |
170 | else | |
171 | printf("."); | |
172 | clear_did(); | |
173 | } | |
174 | ||
175 | pooped() | |
176 | { | |
177 | /* extern long random(); */ | |
178 | ||
179 | switch (random() % 3) { | |
180 | case 0: | |
181 | printf("%cknackered", yytext[0]); | |
182 | break; | |
183 | case 1: | |
184 | printf("%cshagged out", yytext[0]); | |
185 | break; | |
186 | case 2: | |
187 | printf("%cdone in", yytext[0]); | |
188 | break; | |
189 | } | |
190 | } | |
191 | ||
192 | expletive() | |
193 | { | |
194 | /* | |
195 | Blimey | |
196 | Stright a light | |
197 | 'Strewth | |
198 | Cor blimey | |
199 | */ | |
200 | } |