Step1: Start
Step2: Read Input file Name
Step3: Split the input into tokens
Step4: Check if conjunctive is present, then proceed to Step 5 else goto Step6
Step5: Print the message as Compound Statement
Step6: Print the message as Simple Statement
Step7: Stop
Explanation:
This program tells whether the input given is compound sentence or simple one. Its easy, just check the scanned symbol with some conjunctives and if they are found, then its compound sentence. Else a simple one. We use a flag variable in this code which is initially 0 indicating a simple sentence. If any conjunctives are matched, set the flag to 1. at the end, if flag=1 then compound sentence, else simple sentence.
%{
int flag=0;
%}
Declaration section with flag variables set to 0.
%%
.+[ \t]+[Aa][Nn][Dd][ \t]+.+ {flag=1;}
.+[ \t]+[Oo][Rr][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][Uu][Tt][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][eE][Cc][Aa][Uu][Ss][Ee][ \t]+.+ {flag=1;}
.+[ \t]+[Nn][Ee][Vv][Ee][Rr][Tt][Hh][Ee][Ll][Ee][Ss][Ss][ \t]+.+ {flag=1;}
. ;
%%
%%
.+[ \t]+[Aa][Nn][Dd][ \t]+.+ {flag=1;}
.+[ \t]+[Oo][Rr][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][Uu][Tt][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][eE][Cc][Aa][Uu][Ss][Ee][ \t]+.+ {flag=1;}
.+[ \t]+[Nn][Ee][Vv][Ee][Rr][Tt][Hh][Ee][Ll][Ee][Ss][Ss][ \t]+.+ {flag=1;}
. ;
%%
Scan the input symbol with any of the Conjunctives like and, or, but, because, nevertheless. if matched, set flag to 1.
regex for these conjunctives are self explanatory. see basics of Lex article to learn what is regex.
main()
{
printf(“Enter text:\n”);
yylex();
if (flag==1)
printf(“Compound Sentence”);
else
printf(“Simple Sentence”);
}
main()
{
printf(“Enter text:\n”);
yylex();
if (flag==1)
printf(“Compound Sentence”);
else
printf(“Simple Sentence”);
}
This is user subroutine. ask user for input sentence. and call yylex() for tokenising.
At the end, if flag=1, print compound. else, print simple sentence.
2 comments
Write commentsthis is not giving output as compound or simple. It simply take the compound and remove it from the sentence.
Replyinput:- I am sick and tired.
output I am sick tired.
Hey Priyanka,
ReplyPlease check if you missed some line. Code is tested and there is no error. Thanks
Share your views about this article!