From 5b54c1d51afad68d497a14d8c5e3a9fc852d5f20 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 16 Apr 2021 10:02:24 +0530 Subject: add prog 4 --- .gitignore | 1 + 4/input | 5 +++++ 4/main.l | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 4/input create mode 100644 4/main.l diff --git a/.gitignore b/.gitignore index 03567fc..595a3c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ outputs +*output* diff --git a/4/input b/4/input new file mode 100644 index 0000000..7f0cc0b --- /dev/null +++ b/4/input @@ -0,0 +1,5 @@ +int main() { + int n; + printf("hello world"); + scanf("%d", &n); +} diff --git a/4/main.l b/4/main.l new file mode 100644 index 0000000..f768382 --- /dev/null +++ b/4/main.l @@ -0,0 +1,33 @@ +%{ + +int scans = 0; +int prints = 0; +%} + +%% +scanf { + scans++; + fprintf(yyout, "readf"); +}; +printf { + prints++; + fprintf(yyout, "writef"); +} +; fprintf(yyout, "%s", yytext); +\n fprintf(yyout, "\n"); +%% + +int main(void) { + yyin=fopen("4/input", "r+"); + yyout=fopen("4/output", "w"); + yylex(); + printf("%d printf occurrences\n", prints); + printf("%d scanf occurrences\n", scans); +} + +int yywrap() +{ +exit(0); + return(1); +} + -- cgit v1.2.3