diff options
author | Akshay <[email protected]> | 2021-04-09 07:42:26 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-09 07:42:26 +0100 |
commit | 5ea5a4b62486e2c1c06c7483dfa83581837581b2 (patch) | |
tree | cbe54c5cbb5babc80d54c45ce1e0c42317ed07a2 /3 |
init
Diffstat (limited to '3')
-rw-r--r-- | 3/input | 7 | ||||
-rw-r--r-- | 3/main.l | 36 |
2 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,7 @@ | |||
1 | 1 2 3 4 | ||
2 | -1 -2 -3 -4 | ||
3 | 1.1 2.2 | ||
4 | -1.1 -2.2 | ||
5 | 3.-7 3.+7 -3.-7 +3.+7 | ||
6 | 1/2 1/3 1/4 1/5 | ||
7 | -1/2 -1/3 -1/0 -73849/5678 | ||
diff --git a/3/main.l b/3/main.l new file mode 100644 index 0000000..ebac3d7 --- /dev/null +++ b/3/main.l | |||
@@ -0,0 +1,36 @@ | |||
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 | %% | ||
22 | |||
23 | int main(void) { | ||
24 | yylex(); | ||
25 | printf("%d positive integers\n" , posint); | ||
26 | printf("%d positive fractions\n" , posfrac); | ||
27 | printf("%d negative integers\n" , negint); | ||
28 | printf("%d negative fractions\n" , negfrac); | ||
29 | printf("%d errors\n" , errors); | ||
30 | } | ||
31 | |||
32 | int yywrap() | ||
33 | { | ||
34 | return(1); | ||
35 | } | ||
36 | |||