%{ #include #include #include int lineno = 1, sentno = 0, parno = 0; %} %x INPARAGRAPH %x INSENTENCE whitespace [ \t]+ optwhitespace [ \t]* emptyline ^{optwhitespace}\n sentdelim [.?!] sentbegcont [^ \t\n][^.?!\n]+$ sentend [^ \t\n][^.?!\n]*{sentdelim} %% {emptyline} { ++lineno; } {emptyline} { ++lineno; BEGIN INITIAL; } {emptyline} { printf("\t*** Paragraph ended before sentence finishes\n"); ++lineno; BEGIN INITIAL; } <*>\n { ++lineno; } {optwhitespace}/[^ \t\n] { ++parno; BEGIN INPARAGRAPH; printf("\n+++ Paragraph %d begins at line %d\n", parno, lineno); } {optwhitespace} { } {sentbegcont} { ++sentno; printf("\tSentence %d at line %d: %s >>\n", sentno, lineno, yytext); BEGIN INSENTENCE; } {sentbegcont} { printf("\t\t>> %s >>\n", yytext); } {sentend}/[ \t\n]+ { ++sentno; printf("\tSentence %d at line %d: %s\n", sentno, lineno, yytext); } {sentend}/[ \t\n]+ { printf("\t\t>> %s\n", yytext); BEGIN INPARAGRAPH; } %% int yywrap () { return 1; } int main ( int argc, char *argv[] ) { if (argc > 1) yyin = (FILE *)fopen(argv[1],"r"); yylex(); exit(0); }