Lex programm to recgnize static words from english

, by Prashant Gunjal

/*
Aim : Write a programm to recgnize static words from english
*/
%{
#include<stdio.h>
%}

verb is|are|was|were
adjective good|bad|big|small
preposition this|under|below
adverb happely|gracefully
space [ \n]+
noune [a-zA-Z]+

%%
{verb} {fprintf(yyout,"\n%s\t\tVERB",yytext);}
{adverb} {fprintf(yyout,"\n%s\t\tADVERB",yytext);}
{adjective} {fprintf(yyout,"\n%s\t\tADJECTIVE",yytext);}
{noune} {fprintf(yyout,"\n%s\t\tNOUNE",yytext);}
. {;}
%%

int main()
{
yyout=fopen("out.txt","w");
yylex();
fclose(yyout);
}


0 comments: