-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWordLineCharCount.l
59 lines (49 loc) · 963 Bytes
/
WordLineCharCount.l
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%{
#include<string.h>
int wordsCount = 0;
int lineCount = 1;
int charactersCount = 0;
int numbersCount = 0;
int spacesCount = 0;
int commaCount = 0;
int fullStopCount = 0;
%}
%%
[0-9]+ {
numbersCount++;
charactersCount += (int)strlen(yytext);
}
[ ]+ {
spacesCount++;
charactersCount++;
}
, {
commaCount++;
charactersCount++;
}
\. {
fullStopCount++;
charactersCount++;
}
[a-zA-Z0-9']+ {
wordsCount++;
charactersCount += (int)strlen(yytext);
}
. {
charactersCount++;
}
\n {
lineCount++;
charactersCount++;
}
%%
int main() {
yylex();
printf("Number of words: %d\n", wordsCount);
printf("Number of lines: %d\n", lineCount);
printf("Number of characters: %d\n", charactersCount);
printf("Number of numbers: %d\n", numbersCount);
printf("Number of spaces: %d\n", spacesCount);
printf("Number of commas: %d\n", commaCount);
printf("Number of full stops: %d\n", fullStopCount);
}