Sharecodepoint popular queries

Saturday, 23 February 2019

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<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: <./a.out> <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);

0 comments:

Post a comment

 

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