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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!