Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ucla-cs!zen!ucbvax!decvax!tektronix!tekgen!tekred!games-request From: games-request@tekred.TEK.COM Newsgroups: comp.sources.games Subject: v02i033: pig - simple pig-latin translator Message-ID: <1546@tekred.TEK.COM> Date: Fri, 28-Aug-87 20:05:27 EDT Article-I.D.: tekred.1546 Posted: Fri Aug 28 20:05:27 1987 Date-Received: Sun, 30-Aug-87 06:45:47 EDT Sender: billr@tekred.TEK.COM Lines: 92 Approved: billr@tekred.TEK.COM Submitted by: root Comp.sources.games: Volume 2, Issue 33 Archive-name: pig [Here's a simple pig-latin translator in lex. I added the Makefile and fixed a bug. It's my recollection that pig-latin is actual a little more complex than this, but hey, I don't write 'em - I just post 'em. -br] [P.S. How about some more games? My queue is empty.] [[This is a lex file for a pig-latin translator. If you don't know what pig-latin is or are too young to remember... It was a "language" popular in the 40-50's. The rules are simple, move the first letter of each word to the end of the word and add an 'a'. For example; "pig-latin" becomes "igpa-atinla". I wrote this as an exercise trying to learn lex. It needs some cleaning up, but it works as is. Words that are all capitals are not parsed correctly, yet. Anyway, enjoy. ************************************************ * Scotty * Adapt * * ihnp4!killer!ozdaltx!sysop * Enjoy * * "Ad Venerem Securiorem" * Survive *]] ---------------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh Makefile <<'END_OF_Makefile' X# Makefile for pig - Pig-Latin translator X Xpig: pig.l X lex pig.l X cc -o pig lex.yy.c -ll X rm lex.yy.c END_OF_Makefile if test 102 -ne `wc -c pig.l <<'END_OF_pig.l' X/* PIG - a pig-latin translator */ X X%{ X#include Xchar *c, start; X%} X%% X[A-Za-z]+ { X if(yyleng >=2){ X c=yytext; X if(isupper(yytext[0])) X start = tolower(yytext[0]); X else X start = yytext[0]; X c++; X if(isupper(yytext[0])) X *c=toupper(*c); X printf("%s%ca",c,start); X } else { X ECHO; X } X} X%% Xmain() X{ X yylex(); X} END_OF_pig.l if test 331 -ne `wc -c