| 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 | %option noyywrap |
| 19 | |
| 20 | %{ |
| 21 | #include<time.h> |
| 22 | void eos(void); |
| 23 | void plastc(void); |
| 24 | char caseify(char); |
| 25 | void I(void); |
| 26 | void bloody(void); |
| 27 | void set_did(short); |
| 28 | void clear_did(void); |
| 29 | void dintI(void); |
| 30 | void pooped(void); |
| 31 | void 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(); } |
| 80 | oothe | |
| 81 | e[ei]the { printf("%c%cve", yytext[0], yytext[0]); } |
| 82 | ooth | |
| 83 | eeth { printf("%c%cf", yytext[0], yytext[0]); } |
| 84 | [aei]the { printf("%cvv",yytext[0]); plastc(); } |
| 85 | th putchar('v'); |
| 86 | a[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]); |
| 89 | ing{EW} { printf("in'"); eos(); } |
| 90 | [^dg]get+[^h] printf("%cge'%c",yytext[0],yytext[yyleng-1]); |
| 91 | ail printf("aiw"); |
| 92 | any printf("enny"); |
| 93 | [rSs]ay{EW} { printf("%cigh",yytext[0]); eos(); } |
| 94 | way printf("why"); |
| 95 | [BbHh]it{EW} { printf("%ci'",yytext[0]); eos(); } |
| 96 | ait{EW} { printf("ite"); eos(); } |
| 97 | ime{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 | |
| 109 | void eos() |
| 110 | { |
| 111 | if (yytext[yyleng-1] == '.') |
| 112 | dintI(); |
| 113 | else |
| 114 | unput(yytext[yyleng-1]); |
| 115 | } |
| 116 | |
| 117 | void plastc() |
| 118 | { |
| 119 | unput(yytext[yyleng-1]); |
| 120 | } |
| 121 | |
| 122 | char caseify(c) |
| 123 | char c; |
| 124 | { |
| 125 | if (yytext[0] <= 'Z') |
| 126 | return (c - ' '); |
| 127 | else |
| 128 | return (c); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | void 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 | |
| 142 | static short b_count = 0; |
| 143 | static short b_which = 0; |
| 144 | |
| 145 | void 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 | |
| 157 | static short did = 0; |
| 158 | |
| 159 | void set_did(val) |
| 160 | short val; |
| 161 | { |
| 162 | did = val; |
| 163 | } |
| 164 | |
| 165 | void clear_did() |
| 166 | { |
| 167 | did = 0; |
| 168 | } |
| 169 | |
| 170 | void 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 | |
| 183 | void 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 | |
| 200 | void expletive() |
| 201 | { |
| 202 | /* |
| 203 | Blimey |
| 204 | Stright a light |
| 205 | 'Strewth |
| 206 | Cor blimey |
| 207 | */ |
| 208 | } |