Write A Program To Print Hello World Using Lex

 


How to write lex program ?


first write a lex program in notepad then save with .l extension. next step is open cmd(Command prompt) then open directory in which your program is saved. then 3 step to run lex program let's see

  1. flex filename.l
  2. gcc lex.yy.c
  3. a.exe

Code


%{
#include<stdlib.h>
%}
%%
("hi"|"HI")"\n" {printf("\nHello Sir,Good Morning\n");}
("bye"|"BYE")"\n" {printf("\nBye, Take Care\n");}
. {yyerror();}
%%
int main()
{
yylex();
return 0;
}
int yywrap(void)
{
return 0;
}

int yyerror(){
printf("Enter hi,HI,bye or BYE");
}


Output




in output when successful compile then just type hi,HI,bye and BYE and lex program is give you replay which is set by you.

Comments

Popular posts from this blog

Create a Student registration form using following tags form,input,textarea,button,select,optio. The registration form must consist of following information: first name,Middle name,last name, gender(use radio button),address,phone no,email id,hobbies(use checkbox),city,state,country,collage name (use dropdown menu).