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