RosettaCodeData/Task/I-before-E-except-after-C/C/i-before-e-except-after-c.c
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

32 lines
849 B
C

%{
/*
compilation and example on a GNU linux system:
$ flex --case-insensitive --noyywrap --outfile=cia.c source.l
$ make LOADLIBES=-lfl cia
$ ./cia < unixdict.txt
I before E when not preceded by C: plausible
E before I when preceded by C: implausible
Overall, the rule is: implausible
*/
int cie, cei, ie, ei;
%}
%%
cie ++cie, ++ie; /* longer patterns are matched preferentially, consuming input */
cei ++cei, ++ei;
ie ++ie;
ei ++ei;
.|\n ;
%%
int main() {
cie = cei = ie = ei = 0;
yylex();
printf("%s: %s\n","I before E when not preceded by C", (2*ei < ie ? "plausible" : "implausible"));
printf("%s: %s\n","E before I when preceded by C", (2*cie < cei ? "plausible" : "implausible"));
printf("%s: %s\n","Overall, the rule is", (2*(cie+ei) < (cei+ie) ? "plausible" : "implausible"));
return 0;
}