10 REM >SentSlw 20 REM by Steven Flintham 30 REM 40 REM Friday 15th April 1994 50 REM Saturday 16th April 1994 60 REM 70 REM This is a completely new version and is based entirely on 80 REM 'phrase substitution' 90 : 100 MODE 7:width%=39 110 PROCinit 120 REPEAT 130 PROCgenerate_sentence 140 UNTIL FALSE 150 END 160 : 170 DEF PROCinit 180 LOCAL read%,clear% 190 DIM template$(100),component$(9000,3),variable%(26),match%(5):REM CHANGED FROM 2000 TO 900 BY CJR 200 FOR clear%=1 TO 26:variable%(clear%)=0:NEXT 210 RESTORE 1060:num_templates%=0 220 REPEAT 230 num_templates%=num_templates%+1 240 READ template$(num_templates%) 250 UNTIL template$(num_templates%)="ZZZ" 260 num_templates%=num_templates%-1 270 RESTORE 1110:num_components%=0 280 REPEAT 290 num_components%=num_components%+1 300 FOR read%=1 TO 3 310 READ component$(num_components%,read%) 320 NEXT 330 UNTIL component$(num_components%,1)="ZZZ" 340 num_components%=num_components%-1 350 ENDPROC 360 : 370 DEF FNS="SentSlw" 380 : 390 DEF PROCgenerate_sentence 400 LOCAL sentence$ 410 IF num_templates%=1 THEN sentence$=FNsubstitute(template$(1)) ELSE sentence$=FNsubstitute(template$(RND(num_templates%))) 420 PROCpretty_print(sentence$) 430 ENDPROC 440 : 450 DEF FNsubstitute(line$) 460 LOCAL left$,right$,mid$ 470 IF INSTR(line$,"<")=0 THEN =line$ 480 left$=LEFT$(line$,INSTR(line$,"<")-1) 490 right$=MID$(line$,INSTR(line$,">")+1) 500 mid$=MID$(line$,INSTR(line$,"<")+1,INSTR(line$,">")-INSTR(line$,"<")-1) 510 line$=left$+FNhandle_subst_comp(mid$)+right$ 520 =FNsubstitute(line$) 530 : 540 DEF FNhandle_subst_comp(subst$) 550 LOCAL match%,return$,var_num% 560 match%=FNfind_subst(subst$) 570 IF match%=0 THEN PRINT "Substitution component '";subst$;"' not recognised.":END 580 IF component$(match%,2)="" THEN return$=FNget_at_random(component$(match%,3)) 590 IF LEN(component$(match%,2))>=3 THEN var_num%=ASC(LEFT$(component$(match%,2),1))-64:variable%(var_num%)=VAL(MID$(component$(match%,2),3)):return$=FNget_at_random(component$(match%,3)) 600 IF LEN(component$(match%,2))=1 THEN var_num%=ASC(component$(match%,2))-64:return$=FNget_item(component$(match%,3),variable%(var_num%)) 610 =return$ 620 : 630 DEF FNfind_subst(subst$) 640 LOCAL match_num%,scan%,clear% 650 FOR clear%=1 TO 5:match%(clear%)=0:NEXT:match_num%=0 660 FOR scan%=1 TO num_components% 670 IF component$(scan%,1)=subst$ THEN match_num%=match_num%+1:match%(match_num%)=scan% 680 NEXT 690 IF match_num%=0 THEN =0 700 IF match_num%=1 THEN =match%(1) 710 =match%(RND(match_num%)) 720 : 730 DEF FNget_at_random(list$) 740 LOCAL num_in_list% 750 num_in_list%=FNnum_in_list(list$) 760 IF num_in_list%=1 THEN =FNget_item(list$,1) ELSE =FNget_item(list$,RND(num_in_list%)) 770 : 780 DEF FNnum_in_list(list$) 790 LOCAL count%,offset% 800 IF INSTR(list$,"~")=0 THEN =1 810 count%=0:offset%=1 820 REPEAT 830 count%=count%+1 840 offset%=INSTR(list$,"~",offset%)+1 850 UNTIL offset%=1 860 =count% 870 : 880 DEF FNget_item(list$,pos%) 890 LOCAL skip% 900 IF INSTR(list$,"~")=0 THEN =list$ 910 IF pos%=1 THEN =LEFT$(list$,INSTR(list$,"~")-1) 920 FOR skip%=1 TO pos%-1 930 list$=MID$(list$,INSTR(list$,"~")+1) 940 NEXT 950 IF INSTR(list$,"~")=0 THEN =list$ 960 =LEFT$(list$,INSTR(list$,"~")-1) 970 : 980 DEF PROCpretty_print(T$) 990 LOCAL A% 1000 REPEAT 1010 IF LEN(T$) ." 1070 DATA "If there was one thing , it was ." 1080 DATA ZZZ 1090 : 1100 REM Components 1110 DATA "Person",,"~" 1120 DATA "Man","S=1","He~Steven~Fred~Chris~Michael" 1130 DATA "Woman","S=2","She~Helen~Lindsey~Caroline" 1140 DATA "person",,"~" 1150 DATA "man","S=1","he~Steven~Fred~Chris~Michael" 1160 DATA "woman","S=2","she~Helen~Lindsey~Caroline" 1170 DATA "his/her","S","his~her" 1180 DATA "he/she","S","he~she" 1190 : 1200 DATA "enjoyed",,"enjoyed~liked~loved" 1210 DATA "did not like",,"did not like~hated~could not stand" 1220 : 1230 DATA "enjoyable thing",,"reading the latest edition of 8BS~going to work~writing <(brilliant )>programs to send in to 8BS~the mindless tedium of backing up collection of discs" 1240 DATA "enjoyable thing",,"programming computer~sleeping late at weekends~laughing at people who said that 8-bit BBC was outdated" 1250 DATA "unpleasant thing",,"backing up discs~talking to people who owned Amigas~power failures just as the latest version of program was being saved" 1260 : 1270 DATA "(brilliant )",,"~brilliant ~great ~novel " 1280 : 1290 DATA ZZZ,ZZZ,ZZZ