Write a lex input file that sill produce a program that counts characters,words,
ID: 3707066 • Letter: W
Question
Write a lex input file that sill produce a program that counts characters,words,lines in a text file and reports that counts.Define a word to be any sequence of letter and/or digits,without punctuation or spaces.Punctuation and white space do not count as words.Write the above program ignoring c sttle comments specified by /* */ i.e comments will be ignored when counting the words,lines,chars in a input fil Write a lex input file that sill produce a program that counts characters,words,lines in a text file and reports that counts.Define a word to be any sequence of letter and/or digits,without punctuation or spaces.Punctuation and white space do not count as words.Write the above program ignoring c sttle comments specified by /* */ i.e comments will be ignored when counting the words,lines,chars in a input filExplanation / Answer
code:
%
{
#include<stdio.h>
#include<stdio.h>
int cno=0,wno=0,lno=0;/*counts of character words and lines*/
%}
characters[a-cA-z]
digit[0-9]
word({character}{digit})+line
%%
{line} {cno++;lno++;}
{word}{wno++;cno+=strlen(yy test);}
{cno++;}
%%
int main(void)
{
yylex();
printf("number of characters,%d",cno);
printf("number of words:%d",wno);
printf("number of lines:%d",lno);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.