2B) Program to recognize whether a given sentence is simple or compound. [VTU SS&OS]

vtu ss&os 2b
Code:

Algorithm:
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;}
.  ;

%%

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”);
}

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.

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

2 comments

Write comments
Unknown
AUTHOR
6 April 2017 at 21:16 delete

this is not giving output as compound or simple. It simply take the compound and remove it from the sentence.
input:- I am sick and tired.
output I am sick tired.

Reply
avatar
Unknown
AUTHOR
10 April 2017 at 02:10 delete

Hey Priyanka,
Please check if you missed some line. Code is tested and there is no error. Thanks

Reply
avatar

Share your views about this article!