aboutsummaryrefslogtreecommitdiff
path: root/03
diff options
context:
space:
mode:
Diffstat (limited to '03')
-rw-r--r--03/input7
-rw-r--r--03/main.l38
2 files changed, 45 insertions, 0 deletions
diff --git a/03/input b/03/input
new file mode 100644
index 0000000..23cb9b7
--- /dev/null
+++ b/03/input
@@ -0,0 +1,7 @@
11 2 3 4
2-1 -2 -3 -4
31.1 2.2
4-1.1 -2.2
53.-7 3.+7 -3.-7 +3.+7
61/2 1/3 1/4 1/5
7-1/2 -1/3 -1/0 -73849/5678
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%{
2int posint = 0;
3int posfrac = 0;
4int negint = 0;
5int negfrac = 0;
6int errors = 0;
7%}
8
9d [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
25int 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
34int yywrap()
35{
36 return(1);
37}
38