diff options
author | Akshay <[email protected]> | 2021-04-30 17:55:19 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-30 17:55:19 +0100 |
commit | da1764a9f839e1d29b2bee12d35534f71f05c6ff (patch) | |
tree | d410c2191e571f9e6945ed88afd3faa1175675b3 /03/main.l | |
parent | 9ff0cec8b507d9164d8828dcb2a87012e140fdf5 (diff) |
law & order
Diffstat (limited to '03/main.l')
-rw-r--r-- | 03/main.l | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/03/main.l b/03/main.l new file mode 100644 index 0000000..f423e7a --- /dev/null +++ b/03/main.l | |||
@@ -0,0 +1,38 @@ | |||
1 | %{ | ||
2 | int posint = 0; | ||
3 | int posfrac = 0; | ||
4 | int negint = 0; | ||
5 | int negfrac = 0; | ||
6 | int errors = 0; | ||
7 | %} | ||
8 | |||
9 | d [0-9] | ||
10 | |||
11 | %% | ||
12 | (\+?|-){d}*\.-{d}+ errors++; // invalid numbers | ||
13 | (\+?|-){d}*\.\+{d}+ errors++; // invalid numbers | ||
14 | \+?{d}+\/[1-9]{d}* posfrac++; | ||
15 | -{d}+\/[1-9]{d}* negfrac++; | ||
16 | (\+?|-){d}+\/{d}+ errors++; | ||
17 | \+?{d}+ posint++; | ||
18 | -{d}+ negint++; | ||
19 | \+?{d}*\.{d}+ posfrac++; | ||
20 | -{d}*\.{d}+ negfrac++; | ||
21 | \n ; | ||
22 | . ; | ||
23 | %% | ||
24 | |||
25 | int main(void) { | ||
26 | yylex(); | ||
27 | printf("%d positive integers\n" , posint); | ||
28 | printf("%d positive fractions\n" , posfrac); | ||
29 | printf("%d negative integers\n" , negint); | ||
30 | printf("%d negative fractions\n" , negfrac); | ||
31 | printf("%d errors\n" , errors); | ||
32 | } | ||
33 | |||
34 | int yywrap() | ||
35 | { | ||
36 | return(1); | ||
37 | } | ||
38 | |||