aboutsummaryrefslogtreecommitdiff
path: root/2/main.l
blob: 872c7bc2e44ddf7fc8c5ba3209112258d97ec48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%{
int word_count = 0;
int line_count = 0;
int char_count = 0;
int para_count = 0;
int spaces = 0;
%}

%%
\n line_count++;
[ \t] spaces++;
[A-Za-z]+ { word_count++; char_count+=yyleng;};
\n\n para_count++;
<<EOF>> {para_count++; return 1;};
. ;
%%

int main(void) {
    yylex();
    printf("%d lines\n", line_count);
    printf("%d words\n", word_count);
    printf("%d blanks\n", spaces);
    printf("%d characters\n", char_count);
    printf("%d paragraphs\n", para_count);
}

int yywrap() {
    return(1);
}