From da1764a9f839e1d29b2bee12d35534f71f05c6ff Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 30 Apr 2021 22:25:19 +0530 Subject: law & order --- 03/input | 7 +++++++ 03/main.l | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 03/input create mode 100644 03/main.l (limited to '03') diff --git a/03/input b/03/input new file mode 100644 index 0000000..23cb9b7 --- /dev/null +++ b/03/input @@ -0,0 +1,7 @@ +1 2 3 4 +-1 -2 -3 -4 +1.1 2.2 +-1.1 -2.2 +3.-7 3.+7 -3.-7 +3.+7 +1/2 1/3 1/4 1/5 +-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 @@ +%{ +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); +} + -- cgit v1.2.3