-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTokenCount.l
50 lines (37 loc) · 1.13 KB
/
TokenCount.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
%{
int operatorsCount = 0;
int identifiersCount = 0;
int keywordsCount = 0;
int specialSymbolsCount = 0;
%}
KEYWORDS (auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)
ARITHMETIC (\+|-|\*|\/|%|\+\+|--)
RELATIONAL (==|!=|>=|<=|>|<)
LOGICAL (&&|\|\||!)
BITWISE (\^|\||&|<<|>>)
ASSIGNMENT (=|\+=|-=|\*=|\/=|%=)
OPERATORS ({ARITHMETIC}|{RELATIONAL}|{LOGICAL}|{BITWISE}|{ASSIGNMENT})
SPECIAL_SYMBOLS [;{}\(\)\[\]@#$,"`~!&?\\\.\*]
%%
[\s]+ /* ignore whitespaces */
{OPERATORS} {
operatorsCount++;
}
{KEYWORDS} {
keywordsCount++;
}
[a-zA-Z_][a-zA-Z0-9_]* {
identifiersCount++;
}
{SPECIAL_SYMBOLS} {
specialSymbolsCount++;
}
. {}
%%
int main() {
yylex();
printf("\n\nNumber of Operators: %d\n", operatorsCount);
printf("Number of Identifiers: %d\n", identifiersCount);
printf("Number of Keywords: %d\n", keywordsCount);
printf("Number of Special Symbols: %d\n", specialSymbolsCount);
}