From 5ea5a4b62486e2c1c06c7483dfa83581837581b2 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 9 Apr 2021 12:12:26 +0530 Subject: init --- 2/input | 5 +++++ 2/main.l | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 2/input create mode 100644 2/main.l (limited to '2') diff --git a/2/input b/2/input new file mode 100644 index 0000000..5ad8acb --- /dev/null +++ b/2/input @@ -0,0 +1,5 @@ +this is the first para text. +another line in this para. + +this is the second para text. +another line in this para. diff --git a/2/main.l b/2/main.l new file mode 100644 index 0000000..872c7bc --- /dev/null +++ b/2/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