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