|
|
1.1 root 1: %{
2: #include "style.h"
3: #include "names.h"
4: #include "conp.h"
5: int part = 0;
6: int style = 1;
7: int pastyle = 0;
8: int pstyle = 0;
9: int lstyle = 0;
10: int rstyle = 0;
11: int estyle = 0;
12: int lthresh;
13: int rthresh;
14: int nomin;
15: char s[SCHAR];
16: char *sptr = s;
17: struct ss sent[SLENG];
18: struct ss *sentp = sent;
19: float wperc();
20: float sperc();
21: float typersent();
22: float vperc();
23: int numsent = 0;
24: int qcount = 0;
25: int icount = 0;
26: long vowel = 0;
27: long numwds = 0;
28: long twds = 0;
29: long numnonf = 0;
30: long letnonf = 0;
31: int maxsent = 0;
32: int maxindex = 0;
33: int minsent = 30;
34: int minindex = 0;
35: int simple = 0;
36: int compound = 0;
37: int compdx = 0;
38: int prepc = 0;
39: int conjc = 0;
40: int complex = 0;
41: int tobe = 0;
42: int adj = 0;
43: int infin = 0;
44: int pron = 0;
45: int passive = 0;
46: int aux = 0;
47: int adv = 0;
48: int verbc = 0;
49: int tverbc = 0;
50: int noun = 0;
51: long numlet = 0;
52: int beg[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
53: int sleng[50];
54: int j,jj,i;
55: int comma = 0;
56: int cflg;
57: int question;
58: int quote = 0;
59: char *st;
60: int initf = 0;
61: int over = 1;
62: %}
63: C [A-DF-Za-z]
64: %%
65: ^{C}:.+ {
66: collect:
67: sentp->cc = sentp->ic = yytext[0];
68: collect1:
69: sentp->leng = yyleng-2;
70: sentp++->sp = sptr;
71: if(sentp >= &sent[SLENG-1]){
72: if(over)fprintf(stderr,"sentence %d too many words\n",numsent+2);
73: over=0;
74: sentp--;
75: }
76: if(sptr+yyleng >= &s[SCHAR-1]){
77: if(over)fprintf(stderr,"sentence %d too many characters\n",numsent+2);
78: over=0;
79: }
80: else {
81: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
82: *sptr++ = '\0';
83: }
84: }
85: ^";:".+ {
86: sentp->cc=END;
87: sentp->ic = ';';
88: goto collect1;
89: }
90: ^",:".+ {
91: comma++;
92: goto collect;
93: }
94: ^",:"[:,-]+ {
95: comma++;
96: goto collect;
97: }
98: [\n] ;
99: ^"\":".+ {
100: goto collect;
101: }
102: ^E:"/." {
103: cflg = 1;
104: goto sdone;
105: }
106: ^E:.+ {
107: cflg = 0;
108: sdone:
109: over=1;
110: sentp->cc=sentp->ic=END;
111: sentp++->sp = sptr;
112: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
113: *sptr++='\0';
114: if(yytext[2]=='?')question=1;
115: else question=0;
116:
117: jj=0;
118: if(quote == 1 && sent[jj].cc == ED){
119: sent[jj].cc = VERB;
120: quote = 0;
121: }
122: if(sent[jj].cc=='"')jj++;
123: if(sent[jj].cc==SUBCONJ){
124: if(sent[jj+1].cc == ','){
125: sent[jj].cc=ADV;
126: jj += 2;
127: comma--;
128: }
129: else {
130: jj=scan(1,',',0);
131: if(jj != -1)jj++;
132: comma--;
133: }
134: }
135: if(jj != -1){
136: if(sent[jj].cc==CONJ || sent[jj].cc=='"')jj++;
137: while((jj=scan(jj,END,cflg)) != -1){
138: jj++;
139: if(sent[jj].cc == SUBCONJ && sent[jj+1].cc == ','){
140: sent[jj].cc=ADV;
141: jj += 2;
142: comma--;
143: }
144: }
145: }
146: st = sent[i].sp;
147: if(*(st+1) == '"')
148: if(*st == '?' || *st == '!')quote = 1;
149: outp();
150: sptr=s;
151: sentp=sent;
152: comma=0;
153: }
154: ;.+ {
155: if(style){
156: nomin = atoi(&yytext[1]);
157: }
158: ;
159: }
160: %%
161: yywrap(){
162: int ii;
163: int ml,mg,lsum,gsum;
164: float aindex, avl, avw;
165: float cindex,kindex,findex,fgrad;
166: float syl, avsy, adjs,snonf;
167:
168: if(style){
169: if(numwds == 0 || numsent == 0)exit(0);
170: avw = (float)(numwds)/(float)(numsent);
171: avl = (float)(numlet)/(float)(numwds);
172: aindex = 4.71*avl + .5*avw -21.43;
173: syl = .9981*vowel-.3432*twds;
174: avsy = syl/twds;
175: kindex = 11.8*avsy+.39*avw-15.59;
176: findex = 206.835-84.6*avsy-1.015*avw;
177: if(findex < 30.)fgrad = 17.;
178: else if(findex > 100.) fgrad = 4.;
179: else if(findex > 70.)fgrad=(100.-findex)/10 +5.;
180: else if(findex > 60.)fgrad =(70.-findex)/10+8.;
181: else if(findex >50.)fgrad=(60.-findex)/5+10;
182: else fgrad=(50.-findex)/6.66 +13.;
183: adjs = 100 * (float)numsent/numwds;
184: cindex = 5.89*avl-.3*adjs-15.8;
185: printf("readability grades:\n (Kincaid) %4.1f (auto) %4.1f (Coleman-Liau) %4.1f (Flesch) %4.1f (%4.1f)\n",kindex,aindex,cindex,fgrad,findex);
186: printf("sentence info:\n");
187: printf(" no. sent %d no. wds %ld\n",numsent,numwds);
188: printf(" av sent leng %4.1f av word leng %4.2f\n",avw,avl);
189: printf(" no. questions %d no. imperatives %d\n",qcount,icount);
190: if(numnonf != 0){
191: snonf = (float)(letnonf)/(float)(numnonf);
192: }
193: printf(" no. nonfunc wds %ld %4.1f%% av leng %4.2f\n",numnonf,(float)(numnonf)*100/numwds,snonf);
194: mg = avw + 10.5;
195: if(mg > 49)mg = 49;
196: ml = avw - 4.5;
197: if(ml <= 0)ml = 1;
198: else if(ml > 49)ml = 48;
199: gsum = lsum = 0;
200: for(ii=0;ii<50;ii++){
201: if(ii < ml)lsum += sleng[ii];
202: else if(ii > mg)gsum+= sleng[ii];
203: }
204: printf(" short sent (<%d)%3.0f%% (%d) long sent (>%d) %3.0f%% (%d)\n",ml,sperc(lsum),lsum,mg,sperc(gsum),gsum);
205: printf(" longest sent %d wds at sent %d; shortest sent %d wds at sent %d\n",maxsent,maxindex,minsent,minindex);
206: printf("sentence types:\n");
207: printf(" simple %3.0f%% (%d) complex %3.0f%% (%d)\n",sperc(simple),simple,sperc(complex),complex);
208: printf(" compound %3.0f%% (%d) compound-complex %3.0f%% (%d)\n",sperc(compound),compound,sperc(compdx),compdx);
209: printf("word usage:\n");
210: printf(" verb types as %% of total verbs\n");
211: printf(" tobe %3.0f%% (%d) aux %3.0f%% (%d) inf %3.0f%% (%d)\n",vperc(tobe),tobe,vperc(aux),aux,vperc(infin),infin);
212: if(verbc != 0)adjs = (float)(passive)*100/(float)(verbc);
213: else adjs=0;
214: printf(" passives as %% of non-inf verbs %3.0f%% (%d)\n",adjs,passive);
215: printf(" types as %% of total\n");
216: printf(" prep %3.1f%% (%d) conj %3.1f%% (%d) adv %3.1f%% (%d)\n",wperc(prepc),prepc,wperc(conjc),conjc,wperc(adv),adv);
217: printf(" noun %3.1f%% (%d) adj %3.1f%% (%d) pron %3.1f%% (%d)\n",wperc(noun),noun,
218: wperc(adj),adj,wperc(pron),pron);
219: printf(" nominalizations %3.0f %% (%d)\n",wperc(nomin),nomin);
220: printf("sentence beginnings:\n");
221: ii=beg[0]+beg[7]+beg[6]+beg[3]+beg[8];
222: printf(" subject opener: noun (%d) pron (%d) pos (%d) adj (%d) art (%d) tot %3.0f%%\n",
223: beg[0],beg[7],beg[6],beg[3],beg[8],sperc(ii));
224: printf(" prep %3.0f%% (%d) adv %3.0f%% (%d) \n",sperc(beg[9]),beg[9],sperc(beg[4]),beg[4]);
225: printf(" verb %3.0f%% (%d) ",sperc(beg[1]+beg[10]+beg[12]),beg[1]+beg[10]+beg[12]);
226: printf(" sub_conj %3.0f%% (%d) conj %3.0f%% (%d)\n",sperc(beg[13]),beg[13],sperc(beg[5]),beg[5]);
227: printf(" expletives %3.0f%% (%d)\n",sperc(beg[14]),beg[14]);
228: }
229: return(1);
230: }
231: float
232: wperc(a)
233: {
234: return((float)(a)*100/numwds);
235: }
236: float
237: sperc(a)
238: {
239: return((float)(a)*100/numsent);
240: }
241: float
242: typersent(a)
243: {
244: return((float)(a)/numsent);
245: }
246: float
247: vperc(a)
248: {
249: if(tverbc == 0)return(0);
250: return((float)(a)*100/tverbc);
251: }
252: main(argc,argv)
253: char **argv;
254: {
255: while(--argc > 0 && (++argv)[0][0] == '-' ){
256: switch(argv[0][1]){
257: case 's': style=1;
258: continue;
259: case 'p': pastyle=style=1;
260: continue;
261: case 'a': pstyle=style=1;
262: continue;
263: case 'e': estyle = style = 1;
264: continue;
265: case 'l': style=lstyle=1;
266: lthresh = atoi(*(++argv));
267: continue;
268: case 'r':
269: style=rstyle=1;
270: rthresh = atoi(*(++argv));
271: continue;
272: case 'P':
273: part = 1;
274: continue;
275: default:
276: fprintf(stderr,"unknown flag to part %s\n",*argv);
277: exit(1);
278: }
279: argv++;
280: }
281: yylex();
282: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.