896+ Capstone Project is Available: Whatsapp: +91-7011258995, Email: sharecodepoint@gmail.com

Program to count the number of characters, words, spaces, end of lines in a given input file. | Compiler Design Programs | Lex Programs

Compiler Design Lab Program : 

%{
 #include<s;stdio.h>
 Int c=0, w=0, s=0, l=0;
%}
WORD [^ \t\n,\.:]+
EOL [\n]
BLANK [ ]
%%
{WORD} {w++; c=c+yyleng;}
{BLANK} {s++;}
{EOL} {l++;}
. {c++;}
%%
int yywrap()
{
return 1;
}
main(int argc, char *argv[])
{
 If(argc!=2)
 {
 printf(“Usage: <s;./a.out> <s;sourcefile>\n”);
 exit(0);
 }
 yyin=fopen(argv[1],”r”);
yylex();
printf(“No of characters=%d\nNo of words=%d\nNo of
spaces=%d\n No of lines=%d”,c,w,s,l);
} 

Sharecodepoint

Sharecodepoint is the junction where every essential thing is shared for college students in the well-defined packets of codes. We are focused on providing you the best material package like Question papers, MCQ'S, and one NIGHT STUDY MATERIAL. facebook twitter youtube instagram

Post a Comment

Previous Post Next Post

Contact Form