%{ /* break out words, output cap + word(inverted) */ #ifndef lint static char sccsid[] = "@(#)nwords.l 4.2 (Berkeley) 82/11/06"; #endif not lint #include #include #define OUT() for(i=yyleng-1;i>=0; i--)putchar(yytext[i]); putchar('\n') #define OUT1(nam) printf("%c:%s\n",nam,yytext) #define OUTN(string) printf("%s\n",string) #ifdef BSD2_10 #define abbrev_d d_abbrev #endif BSD2_10 #include "names.h" #include "nhash.c" #include "dict.c" #include "ydict.c" #include "abbrev.c" char nt[] = "D:n't"; char qs[] = "c:'s"; char fin[] = "E:."; int NOCAPS = 0; /* if set all caps are turned to lower case */ int i,j; int dot = 0; int first = 1; int qflg,nflg; int cap = 0; %} %p 3000 %a 3300 %o 4500 L [a-z] N [0-9] C [A-Z] A [a-zA-Z] P [a-zA-Z0-9] %% ^[.!].+[\n] { if(dot){ OUTN(fin); dot = 0; first = 1; } printf(":%s",yytext); } May { if(first == 0){ OUT1(NOUN); } else { first = 0; yytext[0] = tolower(yytext[0]); cap = 1; goto wd; } } "U.S." { OUT1(NOUN); } {C}{L}*'[s] { pos(1); if(first==1)first=0; } {C}+['][s] { if(NOCAPS) for(i=0;i0;i--) if(yytext[i] == '.')break; unput(yytext[yyleng-1]); yytext[i] = '\0'; OUT1(NOUN_ADJ); OUTN(fin); first = 1; } ([hH]e"/"[sS]he)|([sS]he"/"[hH]e) { if(NOCAPS) if(isupper(yytext[0]))yytext[0] = tolower(yytext[0]); OUT1(PRONS); } ([hH]is"/"[hH]er)|([hH]er"/"[hH]is) { if(NOCAPS) if(isupper(yytext[0]))yytext[0] = tolower(yytext[0]); OUT1(POS); } [ \t`]*[a-zA-Z0-9.]*("\/"[a-zA-Z0-9.]+)+[']* { if(yytext[yyleng-1] == '.'){ if(ahead() == 0)dot=1; } if(NOCAPS) for(i=0;i1) { if(freopen(argv[1],"r",stdin)==NULL) { fprintf(stderr,"%s: cannot open\n", argv[1]); rc++; }else{ filename=argv[1]; yylex(); OUTN(fin); } argc--; argv++; } } return(rc); } ahead(){ register int c; if(isalnum((c=input()))){ yytext[yyleng++] = '.'; while(!isspace((c=input() ))) yytext[yyleng++] = c; yytext[yyleng] = '\0'; unput(c); return(1); } unput(c); unput('.'); return(0); }