Sharecodepoint popular queries

Saturday, 23 February 2019

Program to count the no of ‘scanf’ and ‘printf’ statements in a C program. Replace them with ‘readf’ and ‘writef’ statements respectively. | Compiler Design Programs | Lex Programs


Compiler Design Program Lab :

%{
#include<stdio.h>
int pc=0, sc=0;
%}
%%
“printf” { fprintf(yyout,”writef”); pc++;}
“scanf” { fprintf(yyout,”readf”); sc++;}
%%
int yywrap()
{
return 1;
}
main(int argc, char *argv[])
{
 if(argc!=2)
 {
 printf(“Usage: <./a.out> <sourcefile> <destn file>\n”);
 exit(0);
 }
 yyin=fopen(argv[1],”r”);
 yyout=fopen(argv[2],”w”);
 yylex();
 printf(“No of printf statements = %d\n No of scanf
statements=%d\n”, pc, sc);

0 comments:

Post a comment

 

Version 23.2.3.4 - 2016 - 2020 - © Sharecodepoint | Made in India. | Copyright Content | Facebook | Twitter | Instagram | Youtube