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