aboutsummaryrefslogtreecommitdiff
path: root/03/main.l
blob: f423e7ab67a2be1f592e840744bfec3edc7960a9 (plain)
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
%{
int posint = 0;
int posfrac = 0;
int negint = 0;
int negfrac = 0;
int errors = 0;
%}

d [0-9]

%%
(\+?|-){d}*\.-{d}+ errors++; // invalid numbers
(\+?|-){d}*\.\+{d}+ errors++; // invalid numbers
\+?{d}+\/[1-9]{d}* posfrac++;
-{d}+\/[1-9]{d}* negfrac++;
(\+?|-){d}+\/{d}+ errors++;
\+?{d}+ posint++;
-{d}+ negint++;
\+?{d}*\.{d}+ posfrac++;
-{d}*\.{d}+ negfrac++;
\n ;
. ;
%%

int main(void) {
    yylex();
    printf("%d positive integers\n"  , posint);
    printf("%d positive fractions\n" , posfrac);
    printf("%d negative integers\n"  , negint);
    printf("%d negative fractions\n" , negfrac);
    printf("%d errors\n" , errors);
}

int yywrap()
{
    return(1);
}