From da1764a9f839e1d29b2bee12d35534f71f05c6ff Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 30 Apr 2021 22:25:19 +0530 Subject: law & order --- 02/main.l | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 02/main.l (limited to '02/main.l') diff --git a/02/main.l b/02/main.l new file mode 100644 index 0000000..872c7bc --- /dev/null +++ b/02/main.l @@ -0,0 +1,29 @@ +%{ +int word_count = 0; +int line_count = 0; +int char_count = 0; +int para_count = 0; +int spaces = 0; +%} + +%% +\n line_count++; +[ \t] spaces++; +[A-Za-z]+ { word_count++; char_count+=yyleng;}; +\n\n para_count++; +<> {para_count++; return 1;}; +. ; +%% + +int main(void) { + yylex(); + printf("%d lines\n", line_count); + printf("%d words\n", word_count); + printf("%d blanks\n", spaces); + printf("%d characters\n", char_count); + printf("%d paragraphs\n", para_count); +} + +int yywrap() { + return(1); +} -- cgit v1.2.3