Anonymous user
I before E except after C: Difference between revisions
m
→{{header|C}}: Included the "overall, the rule is ... something" statement in the output.
m (→{{header|C}}: Included the "overall, the rule is ... something" statement in the output.) |
|||
Line 21:
=={{header|C}}==
Inspired by the J solution, but implemented as a single pass through the data, we have [http://flex.sourceforge.net/ flex] build the finite state machine in C. This may in turn motivate me to provide a second J solution as a single pass FSM. Please find the program output hidden at the top of the source as part of the build and example run.▼
▲Inspired by the J solution, but implemented as a single pass through the data, we have [http://flex.sourceforge.net/ flex] build the finite state machine in C. This may in turn motivate me to provide a second J solution as a single pass FSM.
<lang c>
%{
/*
compilation and example on a GNU linux system:
$ flex --case-insensitive --noyywrap --outfile=cia.c source.l
$ make LOADLIBES=-lfl cia
Line 33 ⟶ 32:
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;
Line 45 ⟶ 44:
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;
}
</lang>
|