Monday, October 12, 2015

PCD PROGRAMS : Implementation of a lexical analyzer to separate subject, verb, & object from given English statement.

Input:

%{
%}

%%
[\t ]+
is |
am |
go|Mango {printf("\n%s: is a verb",yytext);}
I|she|we|he|i {printf("\n%s : is a subject ",yytext);}
eat {printf("\n%s : is a object ",yytext);}
[a-zA-z]+ {printf("\n%s: is not verb",yytext);}


%%

main()}
{
yylex();

Output:
database@database-Veriton-Series:~/Desktop$ lex frist.l
database@database-Veriton-Series:~/Desktop$ cc lex.yy.c -ll
database@database-Veriton-Series:~/Desktop$ ./a.out
i eat mango
i : is a subject 
eat : is a object 
mango: is not verb