Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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:

image text in transcribed

\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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions