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
- flex filename.l
- gcc lex.yy.c
- 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");
}
#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");
}
Comments
Post a Comment