Try your hands on Lex Tools using C.
Store the following code with desired filename having extension .l (dot L)
Use Ubuntu operating system for running the code at ease.
Code to check whether given number is Positive or Negative .
%{
int p=0, n=0,pf=0,nf=0;
%}
%%
[0-9]+ {p++;}
-[0-9]+ {n++;}
[0-9]*.[0-9]+ {pf++;}
-[0-9]*.[0-9]+ {nf++;}
%%
main()
{
printf("Enter the data\t");
yylex();
printf("The positive Number %d \n",p);
printf("The Positive Float %d \n",pf);
printf("The Negative Number %d \n",n);
printf("The Negative Float %d \n",nf);
}
Commands in terminal-
lex filename.l
gcc lex.yy.c -ll
./a.out
Store the following code with desired filename having extension .l (dot L)
Use Ubuntu operating system for running the code at ease.
Code to check whether given number is Positive or Negative .
%{
int p=0, n=0,pf=0,nf=0;
%}
%%
[0-9]+ {p++;}
-[0-9]+ {n++;}
[0-9]*.[0-9]+ {pf++;}
-[0-9]*.[0-9]+ {nf++;}
%%
main()
{
printf("Enter the data\t");
yylex();
printf("The positive Number %d \n",p);
printf("The Positive Float %d \n",pf);
printf("The Negative Number %d \n",n);
printf("The Negative Float %d \n",nf);
}
Commands in terminal-
lex filename.l
gcc lex.yy.c -ll
./a.out
Comments
Post a Comment