Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added third program #2

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions Program_3/Program_3_CountIntDecFrac.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
%{
#include <stdio.h>
int posint = 0, negint = 0, posfloat = 0, negfloat = 0, posfrac = 0, negfrac = 0;
%}

%%
"-"[0-9]+"/"[0-9]+|[0-9]+"/""-"[0-9]+ {printf("%s is negetive fraction",yytext);negfrac++;}
"+"?[0-9]+"/""+"?[0-9]+|"-"[0-9]+"/""-"[0-9]+ {printf("%s is positive fraction",yytext);posfrac++;}
"-"[0-9]+"."?[0-9]+|"-"[0-9]+"."|"-""."[0-9]+ {printf("%s is negetive float",yytext);negfloat++;}
"+"?[0-9]+"."?[0-9]+|"+"?[0-9]+"."|"+"?"."[0-9]+ {printf("%s is positive float",yytext);posfloat++;}
"-"[0-9]+ {printf("%s is negetive integer",yytext);negint++;}
"+"?[0-9]+ {printf("%s is positive integer",yytext);posint++;}
%%
int yywrap()
{
return 1;
}

int main()
{
printf("Enter the number: ");
printf("\nPress Ctrl+D to exit\n");
yylex();
yywrap();
printf("\nNumber type \t\t Count\n");
printf("--------------------------\n");
printf("Positive Integer \t %d\n", posint);
printf("Negative Integer \t %d\n", negint);
printf("Positive Float \t\t %d\n", posfloat);
printf("Negative Float \t\t %d\n", negfloat);
printf("Positive Fraction \t %d\n", posfrac);
printf("Negative Fraction \t %d\n", negfrac);
return 0;
}
Binary file added Program_3/a.out
Binary file not shown.
Loading