Question
IN LEX: Instructions: Modify the original code to count the times a number occurs. A letter(alphabet) is defined as [a-zA-Z]+ (don't use an array) 1.
IN LEX:
Instructions:
Modify the original code to count the times a number occurs. A letter(alphabet) is defined as [a-zA-Z]+ (don't use an array)
1. lex hw1.l
- new file called "lex.yy.c" should appear
compile the new file
gcc -o hw1 lex.yy.c
2 . execute hw1 as follows
./hw1 < /etc/passwd
and examine the output.
Code must run error-free and with no warning using UNIX/Linux.
CODE GIVEN:
int lgths[100]; %% [0-9]+ lgths[yyleng]++; . | ; %% int yywrap() { int i; printf("Length No. Numbers "); for (i=1; i<100; i++) { if (lgths[i] > 0) { printf("%5d%10d ",i,lgths[i]); } } return(1); } main() { yylex(); }
*******************************************************************************************************************************************************
WHAT I HAVE DONE:
int lgths[100]; int count; %% [a-zA-Z]+ lgths[yyleng]++; . | ; %% yywrap() { // need help writing count algorithm to count num of words (not in an array) int i; printf("Length No. Numbers "); for (i=1; i<100; i++) { if (lgths[i] > 0) { printf("%5d%10d ",i,lgths[i]); } } return(1); } main() { yylex(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started