Showing posts with label PCMD. Show all posts
Showing posts with label PCMD. Show all posts

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

PCD PROGRAM : Implementation of a lexical analyzer to count total number of words, character,special Symbolcount and line from given.

Input:



%{
#include<stdio.h>
int w=0,d=0,ln=0,c=0;
int s=0;
%}
%%
[A-Z|a-z]+ {w++; c=c+yyleng;}
[0-9]+ {d++;}
[\n] {ln++;}
. {s=s+yyleng;}
%%
int main(int argc, char *argv[50])
{
FILE *fp;
yylex();
printf(" Wordcount= %d\n Numbercount= %d\n",w,d);
printf(" Charcount= %d\n Linecount= %d\n",c,ln);
printf(" specialSymbolcount= %d\n",s);
}

Output:
database@database-Veriton-Series:~/Desktop$ lex second.l
database@database-Veriton-Series:~/Desktop$ cc lex.yy.c -ll
database@database-Veriton-Series:~/Desktop$ ./a.out
more.mdsb@gmail.com
 Wordcount= 4
 Numbercount= 0
 Charcount= 16
 Linecount= 1
 specialSymbolcount= 3
note: for output display press Ctrl+d