-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathq4-countClassesFunctions.l
52 lines (39 loc) · 1.18 KB
/
q4-countClassesFunctions.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
%{
/*
* Develop a scanner using LEX to count no. of classes, data members, and member
* functions in the given 'C++' program
*
* Author: adarshPatel509
*/
int classesCount = 0;
int dataMembersCount = 0;
int memberFunctionsCount = 0;
%}
DATA_TYPES ((((signed|unsigned|short|long)[ ])?(int|char|double))|(float|bool|void|wchar_t))
IDENTIFIERS ([a-zA-Z_][a-zA-Z0-9_]*)
MEMBER_FUNCTIONS ({DATA_TYPES}[ ]+{IDENTIFIERS}[ ]*\()
DATA_MEMBERS ({DATA_TYPES}[ ]+{IDENTIFIERS})
%%
[\t]+ /* ignore whitespaces */ ;
class {
classesCount++;
}
{MEMBER_FUNCTIONS} {
memberFunctionsCount++;
}
{DATA_MEMBERS} {
dataMembersCount++;
}
[a-zA-Z]* {}
. {}
\n\n {
return 0;
}
%%
main () {
yylex();
printf("Number of classes: %d\n", classesCount);
printf("Number of data members: %d\n", dataMembersCount);
printf("Number of member functions: %d\n", memberFunctionsCount);
return 0;
}