-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.l
51 lines (47 loc) · 948 Bytes
/
error.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
%{
int length_error_stat = 0;
int flc_comm_count = 0;
int open_double = 0;
int open_single = 0;
int valid_number = 0;
%}
DIGIT [0-9]
%%
[$] {valid_number = 0;}
[0-9]+(\.[0-9]+)?(e[+-][0-9]+)? {valid_number = 1;}
[A-Za-z_][A-Za-z0-9_]* {if(yyleng > 31) {length_error_stat = 1;} else {length_error_stat = 0;}}
"\*" {flc_comm_count++;}
"*/" {if(flc_comm_count > 0) {flc_comm_count--;}}
\" {open_double++;}
\' {open_single++;}
.|\n {}
%%
int yywrap(void)
{
return 1;
}
int main(void)
{
yylex();
if(valid_number == 0)
{
printf("Error : Invalid number\n");
}
if(flc_comm_count > 0)
{
printf("Error : Open multiline comment \n");
}
if(length_error_stat == 1)
{
printf("Error : Invalid Identifier length \n");
}
if(open_double % 2 != 0)
{
printf("Error : unmatched double quote found\n");
}
if(open_single % 2 != 0)
{
printf("Error : unmatched single quote found\n");
}
return 0;
}