8-Bit Software Online Conversion

Sentence Generator. SentSlw - Listing

10REM >SentSlw 20REM by Steven Flintham 30REM 40REM Friday 15th April 1994 50REM Saturday 16th April 1994 60REM 70REM This is a completely new versio n and is based entirely on 80REM 'phrase substitution' 90: 100MODE 7:width%=39 110PROCinit 120REPEAT 130PROCgenerate`sentence 140UNTIL FALSE 150END 160: 170DEF PROCinit 180LOCAL read%,clear% 190DIM template$(100),component$(9000, 3),variable%(26),match%(5):REM CHANGED F ROM 2000 TO 900 BY CJR 200FOR clear%=1 TO 26:variable%(clear% )=0:NEXT 210RESTORE 1060:num`templates%=0 220REPEAT 230num`templates%=num`templates%+1 240READ template$(num`templates%) 250UNTIL template$(num`templates%)="ZZ Z" 260num`templates%=num`templates%-1 270RESTORE 1110:num`components%=0 280REPEAT 290num`components%=num`components%+1 300FOR read%=1 TO 3 310READ component$(num`components%,rea d%) 320NEXT 330UNTIL component$(num`components%,1) ="ZZZ" 340num`components%=num`components%-1 350ENDPROC 360: 370DEF FNS="SentSlw" 380: 390DEF PROCgenerate`sentence 400LOCAL sentence$ 410IF num`templates%=1 THEN sentence$= FNsubstitute(template$(1)) ELSE sentence $=FNsubstitute(template$(RND(num`templat es%))) 420PROCpretty`print(sentence$) 430ENDPROC 440: 450DEF FNsubstitute(line$) 460LOCAL left$,right$,mid$ 470IF INSTR(line$,"<")=0 THEN =line$ 480left$=LEFT$(line$,INSTR(line$,"<")- 1) 490right$=MID$(line$,INSTR(line$,">")+ 1) 500mid$=MID$(line$,INSTR(line$,"<")+1, INSTR(line$,">")-INSTR(line$,"<")-1) 510line$=left$+FNhandle`subst`comp(mid $)+right$ 520=FNsubstitute(line$) 530: 540DEF FNhandle`subst`comp(subst$) 550LOCAL match%,return$,var`num% 560match%=FNfind`subst(subst$) 570IF match%=0 THEN PRINT "Substitutio n component '";subst$;"' not recognised. ":END 580IF component$(match%,2)="" THEN ret urn$=FNget`at`random(component$(match%,3 )) 590IF LEN(component$(match%,2))>=3 THE N var`num%=ASC(LEFT$(component$(match%,2 ),1))-64:variable%(var`num%)=VAL(MID$(co mponent$(match%,2),3)):return$=FNget`at` random(component$(match%,3)) 600IF LEN(component$(match%,2))=1 THEN var`num%=ASC(component$(match%,2))-64:r eturn$=FNget`item(component$(match%,3),v ariable%(var`num%)) 610=return$ 620: 630DEF FNfind`subst(subst$) 640LOCAL match`num%,scan%,clear% 650FOR clear%=1 TO 5:match%(clear%)=0: NEXT:match`num%=0 660FOR scan%=1 TO num`components% 670IF component$(scan%,1)=subst$ THEN match`num%=match`num%+1:match%(match`num %)=scan% 680NEXT 690IF match`num%=0 THEN =0 700IF match`num%=1 THEN =match%(1) 710=match%(RND(match`num%)) 720: 730DEF FNget`at`random(list$) 740LOCAL num`in`list% 750num`in`list%=FNnum`in`list(list$) 760IF num`in`list%=1 THEN =FNget`item( list$,1) ELSE =FNget`item(list$,RND(num` in`list%)) 770: 780DEF FNnum`in`list(list$) 790LOCAL count%,offset% 800IF INSTR(list$,"÷")=0 THEN =1 810count%=0:offset%=1 820REPEAT 830count%=count%+1 840offset%=INSTR(list$,"÷",offset%)+1 850UNTIL offset%=1 860=count% 870: 880DEF FNget`item(list$,pos%) 890LOCAL skip% 900IF INSTR(list$,"÷")=0 THEN =list$ 910IF pos%=1 THEN =LEFT$(list$,INSTR(l ist$,"÷")-1) 920FOR skip%=1 TO pos%-1 930list$=MID$(list$,INSTR(list$,"÷")+1 ) 940NEXT 950IF INSTR(list$,"÷")=0 THEN =list$ 960=LEFT$(list$,INSTR(list$,"÷")-1) 970: 980DEF PROCpretty`print(T$) 990LOCAL A% 1000REPEAT 1010IF LEN(T$)<width% THEN PRINT T$:T$= "" ELSE A%=INSTR(T$," ",width%+1):A%=A%+ (A%=0)*-width%:REPEAT:A%=A%-1:UNTIL MID$ (T$,A%,1)=" ":PRINT LEFT$(T$,A%):T$=MID$ (T$,A%+1) 1020UNTIL T$="" 1030ENDPROC 1040: 1050REM Templates 1060DATA "<Person> <enjoyed> <enjoyable thing>." 1070DATA "If there was one thing <perso n> <did not like>, it was <unpleasant th ing>." 1080DATA ZZZ 1090: 1100REM Components 1110DATA "Person",,"<Man>÷<Woman>" 1120DATA "Man","S=1","He÷Steven÷Fred÷Ch ris÷Michael" 1130DATA "Woman","S=2","She÷Helen÷Linds ey÷Caroline" 1140DATA "person",,"<man>÷<woman>" 1150DATA "man","S=1","he÷Steven÷Fred÷Ch ris÷Michael" 1160DATA "woman","S=2","she÷Helen÷Linds ey÷Caroline" 1170DATA "his/her","S","his÷her" 1180DATA "he/she","S","he÷she" 1190: 1200DATA "enjoyed",,"enjoyed÷liked÷love d" 1210DATA "did not like",,"did not like÷ hated÷could not stand" 1220: 1230DATA "enjoyable thing",,"reading th e latest edition of 8BS÷going to work÷wr iting <(brilliant )>programs to send in to 8BS÷the mindless tedium of backing up <his/her> collection of discs" 1240DATA "enjoyable thing",,"programmin g <his/her> computer÷sleeping late at we ekends÷laughing at people who said that <his/her> 8-bit BBC was outdated" 1250DATA "unpleasant thing",,"backing u p <his/her> discs÷talking to people who owned Amigas÷power failures just as the latest version of <his/her> program was being saved" 1260: 1270DATA "(brilliant )",,"÷brilliant ÷g reat ÷novel " 1280: 1290DATA ZZZ,ZZZ,ZZZ