Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site felix.UUCP Path: utzoo!linus!philabs!sdcsvax!sdcrdcf!bmcg!felix!zemon From: zemon@felix.UUCP Newsgroups: net.sources Subject: Pig-Latin Meets LEX Message-ID: <124@felix.UUCP> Date: Mon, 29-Aug-83 16:15:29 EDT Article-I.D.: felix.124 Posted: Mon Aug 29 16:15:29 1983 Date-Received: Fri, 2-Sep-83 23:37:18 EDT Organization: FileNet Corp., Costa Mesa, Ca. Lines: 68 In response to Mark B's Pig-Latin translator, I feel I must post the following version which does the same. Note that by using LEX, this is *much* shorter. PLEASE, I am not trying to start a contest for the shortest Pig-Latin translator program. I just want to show how much easier this is with LEX. Compile it with: lex pig.c cc lex.yy.c -o pig -ll Cheers, Art Zemon FileNet Corporation ...!{ucbvax, decvax}!trw-unix!felix!zemon ---------------------------------------------------------------------- %{ /* * pig * * Translate C comments into Pig-Latin. */ static char rcsid[] = "$Header: RCS/pig.v Revision 1.2 83/08/29 13:01:19 zemon Exp$"; #include %} %START TRANS %% "/*" {ECHO; BEGIN TRANS;} "*/" {ECHO; BEGIN 0;} [A-Za-z]+ {word(yytext);} %% main() { yylex(); } word(s) char *s; { char *root; char first; switch( s[0] ) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': root = s; first = 'y'; break; default: first = s[0]; root = &s[1]; break; } printf("%s-%cay", root, first); return; }