Thursday, 18 September 2014

LEX PROGRAM TO FIND THE COMPOUND SENTENCES

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.

No comments:

Post a Comment

Total Pageviews