-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ideas.c
47 lines (46 loc) · 979 Bytes
/
test_ideas.c
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
%top{
int quit_INDEX = 0, num_vars = 0, num_bracket = 0;
int num_lines = 0, num_operations = 0, bracket_INDEX = 0;
void output_analyse();
}
%%
\n {
if (bracket_INDEX != 0)
{
printf ("you have error in brackets\n");
return;
}
output_analyse();
}
"+"|"-"|"/"|"*" ++num_operations;
"quit" {
printf ("i\'m quiting...\n");
return;
}
[a-zA-Z]+ num_vars++;
"(" {
num_bracket++;
bracket_INDEX++;
}
")" {
bracket_INDEX--;
if (bracket_INDEX < 0)
{
printf ("you have error in brackets\n");
return;
}
}
%%
void output_analyse()
{
printf ("\nyou input\nlines = %d,\noperations = %d,\nvars=%d,\nbrackets=%d\n\n",
num_lines, num_operations, num_vars, num_bracket);
num_vars = 0;
num_bracket = 0;
num_lines = 0;
num_operations = 0;
}
main()
{
yylex();
}