Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART – A
………………………………………………………………………………………………………………………….
2b. b. Program to recognize whether a given sentence is simple or compound.
%{
#include<stdio.h>
int F0=0,F1=0,F2=0,error=0,l1=0,l2=0;
%}
verb am|run|sit|did|study|is|large|go|come
subject [a-zA-Z]+
compnd “and”|”but”|”also”|”either”|”neither”|”yet”|”still”|”consequences”
%%
{verb} { if(F2==1)
l2=1;
F2=1;
if(F1==0)
error=1;
}
{compnd} { F0=1; }
{subject} { if(F1!=0)
l1=1;
F1++;
}
%%
main()
{
printf(“n Enter a sentence: “);
yylex();
if(error==1 || F2==0 || F1==0)
{
printf(“n Invalid sentence”);
exit(0);
}
if(F0==1 && l1==1 && l2==1)
printf(“n Compound sentencen”);
else
printf(” nSimple sentencen”);
}
Leave a ReplyCancel reply