diff options
author | Akshay <[email protected]> | 2021-04-09 07:42:26 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-09 07:42:26 +0100 |
commit | 5ea5a4b62486e2c1c06c7483dfa83581837581b2 (patch) | |
tree | cbe54c5cbb5babc80d54c45ce1e0c42317ed07a2 /2 |
init
Diffstat (limited to '2')
-rw-r--r-- | 2/input | 5 | ||||
-rw-r--r-- | 2/main.l | 29 |
2 files changed, 34 insertions, 0 deletions
@@ -0,0 +1,5 @@ | |||
1 | this is the first para text. | ||
2 | another line in this para. | ||
3 | |||
4 | this is the second para text. | ||
5 | 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 @@ | |||
1 | %{ | ||
2 | int word_count = 0; | ||
3 | int line_count = 0; | ||
4 | int char_count = 0; | ||
5 | int para_count = 0; | ||
6 | int spaces = 0; | ||
7 | %} | ||
8 | |||
9 | %% | ||
10 | \n line_count++; | ||
11 | [ \t] spaces++; | ||
12 | [A-Za-z]+ { word_count++; char_count+=yyleng;}; | ||
13 | \n\n para_count++; | ||
14 | <<EOF>> {para_count++; return 1;}; | ||
15 | . ; | ||
16 | %% | ||
17 | |||
18 | int main(void) { | ||
19 | yylex(); | ||
20 | printf("%d lines\n", line_count); | ||
21 | printf("%d words\n", word_count); | ||
22 | printf("%d blanks\n", spaces); | ||
23 | printf("%d characters\n", char_count); | ||
24 | printf("%d paragraphs\n", para_count); | ||
25 | } | ||
26 | |||
27 | int yywrap() { | ||
28 | return(1); | ||
29 | } | ||