program:
%{
int flag=0;
%}
%%
(" "[aA][nN][Dd]" ")|(" "[oO][Rr]" ")|(" "[bB][uU][tT]" ")|(" "[bB][Ee][Cc][Aa][Uu][Ss][Ee]" ") {flag++;}
.;
%%
main()
{
printf("enter a sentence \n");
yylex();
if(flag==1)
printf("compound sentence \n");
else
printf("simple sentence \n");
}
===============================
(" "[aA][nN][Dd]" ")|(" "[oO][Rr]" ")|(" "[bB][uU][tT]" ")|(" "[bB][Ee][Cc][Aa][Uu][Ss][Ee]" ") this rule matches the and,or,but,because(in upper case also) strings if they are present in the given sentence. If string is found then it is a compound sentence or else it is a simple sentence.
.;
in this . matches the characters other than new line if it is found then ; that means do nothing.
instead of .; this instruction we can use .|\n; can be used this works for long sentences.
%{
int flag=0;
%}
%%
(" "[aA][nN][Dd]" ")|(" "[oO][Rr]" ")|(" "[bB][uU][tT]" ")|(" "[bB][Ee][Cc][Aa][Uu][Ss][Ee]" ") {flag++;}
.;
%%
main()
{
printf("enter a sentence \n");
yylex();
if(flag==1)
printf("compound sentence \n");
else
printf("simple sentence \n");
}
===============================
(" "[aA][nN][Dd]" ")|(" "[oO][Rr]" ")|(" "[bB][uU][tT]" ")|(" "[bB][Ee][Cc][Aa][Uu][Ss][Ee]" ") this rule matches the and,or,but,because(in upper case also) strings if they are present in the given sentence. If string is found then it is a compound sentence or else it is a simple sentence.
.;
in this . matches the characters other than new line if it is found then ; that means do nothing.
instead of .; this instruction we can use .|\n; can be used this works for long sentences.
No comments:
Post a Comment