More you share, more you have!!!

More you share, more you have!!!

LEX program to recognize whether a given sentence is simple or compound.


Q.Write a program using LEX to recognize whether a given sentence is simple or compound.

Source Code-> 

%{

int flag=0;

%}

%%

(""[aA][nN][dD]"")|(""[oO][rR]"")|(""[bB][uU][tT]"") {flag=1;}

%%

int main()

{

printf("Enter the sentence\n");

yylex();

if(flag==1) 

printf("\nCompound sentence\n");

else 

printf("\nSimple sentence\n");

return 0;

}

OUTPUT:->

$lex p2b.l

$cc lex.yy.c –ll

$./a.out

Enter the sentence

I am Pooja

I am Pooja

[Ctrl-d]

Simple sentence

$./a.out

Enter the sentence

CSE or ISE

CSE or ISE

[Ctrl-d]

Compound sentence

Share on Google Plus
    Blogger Comment
    Facebook Comment

3 comments:

  1. how to write a lex program to read roman numbers and sum in decimal

    ReplyDelete
  2. how to write a lex program to read 2 roman numbers and sum in decimal

    ReplyDelete
  3. this is wrong....coz cse or ice is a simple sentence

    ReplyDelete