10
20
30
40 :
100 sentence_count=0
110 ON ERROR GOTO 1930
120 *K.0RUN|M
130 MODE7
140 *.
150 PROCinitialise
160 PRINT
170 REPEAT
180 PROCreadchar
190 UNTILEOF#channel
200 PROCword
210 CLOSE#channel
220 PROCreport
230 END
240 :
1000 DEFPROCreadchar
1010
1020 value=BGET#channel:IFvalue>96 AND value<126:value=value-32
1030 char$=CHR$value
1040 printable=(value>&20 AND value<&7F)
1050 sentence=((INSTR(".",char$) AND (letter_status OR word$="")) OR (INSTR(";!?",char$)))
1060 word=(value=&20 OR value=&A OR value=&D)
1070 punctuation=INSTR("()'[]{}"",:-.;!?",char$)>0
1080 control=((value<&21 AND NOT (value=2 OR word)))
1090 letter=((value>&40 AND value<&5B) OR (value>&60 AND value<&7B)):IF letter THEN letter_status=TRUE
1100 IFprintable AND NOT (letter OR punctuation) THEN word_status=FALSE
1110 IFprintable PROCaddchar
1120 IF sentence PROCword:PROCsentence ELSE IFvalue=2 PROCword:PROCskip ELSE IFword OR control OR value>&7E PROCword
1130 ENDPROC
1140 :
1150 DEFPROCaddchar
1160
1170 word$=word$+char$
1180 char_status=INSTR("AEIOUY",char$)>0
1190 IFchar_status AND vowel_status=FALSE THEN syllable_count=syllable_count+1
1200 IFchar_status THEN vowel_status=TRUE ELSE vowel_status=FALSE
1210 ENDPROC
1220 :
1230 DEFPROCskip
1240
1250 REPEAT
1260 value=BGET#channel
1270 UNTILEOF#channel OR value=7 OR value=&D
1280 ENDPROC
1290 :
1300 DEFPROCword
1310
1320 IFword$="" PROCreset:ENDPROC
1330 print_word$=word$
1340 char$=RIGHT$(word$,1)
1350 IFINSTR("()'[]{}"",:-.!?;",char$) AND LENword$>1 THEN word$=LEFT$(word$,LENword$-1)
1360 IFNOTletter_status THEN word_status=FALSE
1370 IFLENword$>1:suffix$=RIGHT$(word$,2):left$=LEFT$(suffix$,1):right$=RIGHT$(suffix$,1):IFleft$="E" AND (right$="D" OR right$="S"):syllable_count=syllable_count-1
1380 IFLENword$>1 AND RIGHT$(word$,1)="E":end$=RIGHT$(word$,2):left$=LEFT$(word$,1):IFINSTR("AEIOUY",left$)=0:syllable_count=syllable_count-1
1390 len=LENword$:IFlen>2 right3$=RIGHT$(word$,3):IFright3$="IED" OR right3$="IES":syllable_count=syllable_count+1
1400 IFlen>3 right4$=RIGHT$(word$,4):right1$=RIGHT$(right4$,1):IFright1$="S":right3$=LEFT$(right4$,3)
1410 IFlen>2:IFRIGHT$(right3$,2)="LE" AND NOTINSTR("AEIOUY",LEFT$(right3$,1)):syllable_count=syllable_count+1
1420 IFLENword$>1 AND syllable_count<1:syllable_count=1
1430 IFword_status AND syllable_count>2:big_word_count=big_word_count+1
1440 IFword_status AND LENword$>0:word_count=word_count+1
1450 IF(line+LEN(print_word$))>39 PRINT:line=0
1460 IFLENprint_word$>0:line=(line+1+LENprint_word$)MOD40
1470 IFsyllable_count>2 VDU129 ELSE IFLENprint_word$>0 VDU135
1480 PRINTprint_word$;
1490 PROCreset
1500 ENDPROC
1510 :
1520 DEFPROCsentence
1530
1540 PRINT'CHR$131"(";word_count;" words)"'
1550 IFword_count>0:sentence_count=sentence_count+1
1560 total_word_count=total_word_count+word_count
1570 word_count=0
1580 total_big_word_count=total_big_word_count+big_word_count
1590 big_word_count=0
1600 line=0
1610 ENDPROC
1620 :
1630 DEFPROCinitialise
1640 @%=1
1650 INPUT'"Enter text file name: "file$
1660 channel=OPENINfile$
1670 sentece_count=0:total_word_count=0:word_count=0:total_big_word_count=0:big_word_count=0
1680 line=0
1690 PROCreset
1700 ENDPROC
1710 :;
1720 DEFPROCreset
1730
1740 syllable_count=0:word$=""
1750 vowel_status=FALSE:word_status=TRUE:letter_status=FALSE
1760 ENDPROC
1770 :
1780 DEFPROCreport
1790
1800 @%=6
1810 PRINT''CHR$131"Text file name: "CHR$135;file$
1820 PRINTCHR$131"Sentence count ="CHR$135;sentence_count
1830 PRINTCHR$131"Word count ="CHR$135;total_word_count
1840 PRINTCHR$131"Big-word count ="CHR$135;total_big_word_count
1850 @%=&20108
1860 IFsentence_count>0:index=0.4*((total_word_count/sentence_count)+(total_big_word_count*100/total_word_count)) ELSE index=0
1870 PRINTCHR$131"FOG index =";:IFindex<10 VDU130 ELSE IFindex>12 VDU129 ELSE VDU131
1880 PRINT;index" ";
1890 IFindex<10 PRINT"(Safe value)"' ELSE IFindex>12 PRINT"(Too high)" ELSE PRINT"(Moderate)"'
1900 IFtotal_word_count<100 PRINTCHR$129;CHR$136"Word count too small"'
1910 ENDPROC
1920 :
1930
1940 IF ERR=222 PRINT"File not found"''"Pressf0to rerun"'
1950 IF ERR=17:PROCreport
1960 IF ERR<>222 AND ERR<>17:REPORT:PRINT" at line ";ERL
1970 CLOSE#0:END