Question: Help with lex homework : Lex program must add a new variable to count the lines of the input When there is an error message

Help with lex homework :

Lex program must add a new variable to count the lines of the input

When there is an error message enhance it including the line number!

You need to identify a new line and increment this line counter.

____________________________________________________________________

I'm new to lex, if you could explain your solution it will be greatly appreciated!

____________________________________________________________________

CODE GIVEN:

"/*" {

if (cmnt && dbug) fprintf(stderr,

" >>>>>>>> line %d: Possible Nested comment

cmnt = 0;

}

"*/" {

if (!cmnt) printf("%s",yytext); /*print out if it is not in a comment */

cmnt = 0;

}

{ if (!cmnt) printf("%s",yytext);}

%%

int yywrap()

{

return 1;

}

int main()

{

yylex();

}

/*********************************************************************************************************/

Picture of code:

Help with lex homework : Lex program must add a new variable

\begin{tabular}{r|r|c|} 6 & int cmnt =0; \\ 7 & & int dbug =0;/ prints out debug statements / \\ 8 & int ln_cnt=2; / Line counter*/ \\ 9 & \end{tabular}

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!