aboutsummaryrefslogtreecommitdiff
path: root/3/main.l
diff options
context:
space:
mode:
Diffstat (limited to '3/main.l')
-rw-r--r--3/main.l36
1 files changed, 36 insertions, 0 deletions
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%{
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%%
22
23int 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
32int yywrap()
33{
34 return(1);
35}
36