Thursday 1 March 2012

CONSTRUCTION OF PREDICTIVE PARSER TABLE USING C


CONSTRUCTION OF PREDICTIVE PARSER TABLE USING C
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char fin[10][20],st[10][20],ft[20][20],fol[20][20];
int a=0,e,i,t,b,c,n,k,l=0,j,s,m,p;
clrscr();
printf("enter the no. of coordinates\n");
scanf("%d",&n);
printf("enter the productions in a grammar\n");
for(i=0;i<n;i++)
scanf("%s",st[i]);
for(i=0;i<n;i++)
fol[i][0]='\0';
for(s=0;s<n;s++)
{
for(i=0;i<n;i++)
{
j=3;
l=0;
a=0;
l1:if(!((st[i][j]>64)&&(st[i][j]<91)))
{
for(m=0;m<l;m++)
{
if(ft[i][m]==st[i][j])
goto s1;
}
ft[i][l]=st[i][j];
l=l+1;
s1:j=j+1;
}
else
{
if(s>0)
{
while(st[i][j]!=st[a][0])
{
a++;
}
b=0;
while(ft[a][b]!='\0')
{
for(m=0;m<l;m++)
{
if(ft[i][m]==ft[a][b])
goto s2;
}
ft[i][l]=ft[a][b];
l=l+1;
s2:b=b+1;
}
}
}
while(st[i][j]!='\0')
{
if(st[i][j]=='|')
{
j=j+1;
goto l1;
}
j=j+1;
}
ft[i][l]='\0';
}
}
printf("first pos\n");
for(i=0;i<n;i++)
printf("FIRS[%c]=%s\n",st[i][0],ft[i]);
fol[0][0]='$';
for(i=0;i<n;i++)
{
k=0;
j=3;
if(i==0)
l=1;
else
l=0;
k1:while((st[i][0]!=st[k][j])&&(k<n))
{
if(st[k][j]=='\0')
{
k++;
j=2;
}
j++;
}
j=j+1;
if(st[i][0]==st[k][j-1])
{
if((st[k][j]!='|')&&(st[k][j]!='\0'))
{
a=0;
if(!((st[k][j]>64)&&(st[k][j]<91)))
{
for(m=0;m<l;m++)
{
if(fol[i][m]==st[k][j])
goto q3;
}
fol[i][l]=st[k][j];
l++;
q3:
}
else
{
while(st[k][j]!=st[a][0])
{
a++;
}
p=0;
while(ft[a][p]!='\0')
{
if(ft[a][p]!='@')
{
for(m=0;m<l;m++)
{
if(fol[i][m]==ft[a][p])
goto q2;
}
fol[i][l]=ft[a][p];
l=l+1;
}
else
e=1;
q2:p++;
}
if(e==1)
{
e=0;
goto a1;
}
}
}
else
{
a1:c=0;
a=0;
while(st[k][0]!=st[a][0])
{
a++;
}
while((fol[a][c]!='\0')&&(st[a][0]!=st[i][0]))
{
for(m=0;m<l;m++)
{
if(fol[i][m]==fol[a][c])
goto q1;
}
fol[i][l]=fol[a][c];
l++;
q1:c++;
}
}
goto k1;
}
fol[i][l]='\0';
}
printf("follow pos\n");
for(i=0;i<n;i++)
printf("FOLLOW[%c]=%s\n",st[i][0],fol[i]);
printf("\n");
s=0;
for(i=0;i<n;i++)
{
j=3;
while(st[i][j]!='\0')
{
if((st[i][j-1]=='|')||(j==3))
{
for(p=0;p<=2;p++)
{
fin[s][p]=st[i][p];
}
t=j;
for(p=3;((st[i][j]!='|')&&(st[i][j]!='\0'));p++)
{
fin[s][p]=st[i][j];
j++;
}
fin[s][p]='\0';
if(st[i][k]=='@')
{
b=0;
a=0;
while(st[a][0]!=st[i][0])
{
a++;
}
while(fol[a][b]!='\0')
{
printf("M[%c,%c]=%s\n",st[i][0],fol[a][b],fin[s]);
b++;
}
}
else if(!((st[i][t]>64)&&(st[i][t]<91)))
printf("M[%c,%c]=%s\n",st[i][0],st[i][t],fin[s]);
else
{
b=0;
a=0;
while(st[a][0]!=st[i][3])
{
a++;
}
while(ft[a][b]!='\0')
{
printf("M[%c,%c]=%s\n",st[i][0],ft[a][b],fin[s]);
b++;
}
}
s++;
}
if(st[i][j]=='|')
j++;
}
}
getch();
}

OutPut:
Enter the no. of co-ordinates
2
Enter the productions in a grammar
S->CC
C->eC | d
First pos
FIRS[S] = ed
FIRS[C] = ed

Follow pos
FOLLOW[S] =$
FOLLOW[C] =ed$

M [S , e] =S->CC
M [S , d] =S->CC
M [C , e] =C->eC
M [C , d] =C->d

Friday 17 February 2012

IMPLEMENTATION OF LEXICAL ANALYSE USING LEX TOOL (THEORY)


THEORY:
                                         A language for specifying lexical analyzer.
·        There is a wide range of tools for construction of lexical analyzer. The majority of these tools are based on regular expressions.
·        The one of the traditional tools of that kind is lex.We refer to the tool as the lex compiler and to its input specification as the lex language
           LEX:
·        The lex is used in the manner depicted.A specification of the lexical analyzer is preferred by creating a program lex.l in the lex language.
·        Then lex,l is run through the lex compiler to produce a ‘c’program lex.yy.c
·        The program lex.yy.c consists of a tabular representation of a transition diagram constructed from the regular expression of lex.l together with a standard routine that uses the table of recognize leximes.
·        Lex.yy.c is run through the ‘c’ compiler to produce as object program a.out,which is the lexical analyzer that transform as input stream into sequence of tokens.
                      Creating a lexical analyzer with lex is shown in below.

                                    LEX SOURCE PROGRAM



                     LEX SPECIFICATION:
Ø The lex program consists of  three parts
                %{
                declarations
                %}
                %%
                translation rules
                %%
                auxillary procedures

Ø The declarations section includes declarations of variables,constants and regular definitions.
Ø The regular definitions are statements and are used as components of the regular expressions,appearing in the translation rules.
Ø The translation rules of a lex program are of the form

                    P1{action 1}
                    P2{action 2}
                        .
                        .
                        .
                    pn{action n}
Ø Where each pi is a regular expression and each action is a program fragment described in what action the lexical analyzer should be taken when the pattern matches a lexime.
Ø The third section hold whatever auxillary procedures are neede by the actions.Alternately they are compiled separately and loaded with lexical analyzer.
Ø The lexical analyzer works in coordination with parser,when activated by the parser the lexical analyzer begins reading the character by character at a time.
Ø When the string is matched with one of the regular expression pi,then corresponding action will be executed.the repeated search will be made in order to return all tokens ina source string.
                   The lexical analyzer ignores the whitespaces and comments in the parser.



                 SHORTHAND OPERATORS:
                        
                                     1. []    àIt should indicate the set of characters.
                                     2. [^]  àThe string formed by any characters except within of                                                  that characte classes.
                                       3. *   àZero or more instances.    
                                     4. +  àOne or more instances.
                                     5. ?  àZero or one instance.
                                     6. $ àit match the end of the string.
                                     7. ^ àit match the start of the string.
                                     8.  . àit match any character except newline.
                                     9. {m} àspecify the exactly m copies of the previous regular                                expression should be matched.
                                               10. {m,n} àcauses the resulting regular expression to match                                from m to n repetition of the preciding R.E.
                 EXAMPLE:
                          Absence of m:
                          {,n} à{,6}àcauses the resulting RE to match from 0,1,2,3…6.
                          Absence of n:
                          {m,3} à{3,}àcauses the resulting RE to match from 3,4,……….
                                    11. / à matches the preciding RE but only it followed by the                                  following RE.
                 EXAMPLE:
                          0/1 àmatches ‘0’ in the string ‘01’ but would not match anything in                          the string ‘0’or ‘02’.
                          12. |  àeither this or that
                          13. (…)  àcombine more RE
                          14. \  àused to indicate that the character immediately to its right is to              be taken literally.
                          15. ”…..” àinterprete everything within the quotation mark literally                      character c escape sequence the last layer meaning.


                  FOR MORE:
                           ->EARN MORE MONY  
                           ->DOWNLOADS(SOFTWARE,HACKTOOLS,WALLPAPER,etc.,)


JOB VIRUS.COM






FORR


Thursday 2 February 2012

TCP CLIENT SERVER '"CHAT PROGRAM"


// SERVER PROGRAM

#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include<netinet/in.h>
#include<sys/types.h>
int main()
{
char buff[2000];
int sd,connfd,len,n;
struct sockaddr_in servaddr,cliaddr;
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd==-1)
{
    printf(" socket not created in server\n");
    exit(0);
}
else
{
    printf("socket created in  server\n");
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(5207);
if ( bind(sd, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0 )
    printf("Not binded\n");
else
    printf("Binded\n");
if(listen(sd,1)!=0)
    printf("Not listened\n");
else
    printf("Listened\n");
len=sizeof(cliaddr);
connfd=accept(sd,(struct sockaddr *) &cliaddr, &len);
if(connfd!=0) 
    printf("Server accepted client \n");
else
    printf("Server not accepted client\n");
while(n<3)
{
recv(connfd,buff,1024,0);
printf("Serever received msg from client  %s",buff);
Printf(“Type message\n”);
scanf("%s",buff);
Send(connfd,buff,1024,0);//send message to client
n++;
}
close(sd);
return(0);
}




                      
 










// CLIENT PROGRAM

#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include<netinet/in.h>
#include<sys/types.h>
int main()
{
char buff[2000];
int sockfd,connfd,len,n;
struct sockaddr_in servaddr,cliaddr;
// create socket in client side
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
{
    printf(" socket not created in client\n");
    exit(0);
}
else
{
    printf("socket created in  client\n");
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = INADDR_ANY; // ANY address or use specific address
servaddr.sin_port = htons(7802);  // Port address
// client connected to server using server address
if(connect(sockfd,(struct sockaddr *)&servaddr, sizeof(servaddr) )!=0)
{
    printf("client not connected to server\n");
    exit(0);
}
else
{
    printf("client connected to server\n");
}
While(n<3)
{
    printf("Type ur client message\n");
    scanf("%s",buff);
// send  msg to server
   send(sockfd,buff,1024,0);
//recive msg
recv(sockfd,buff,1024,0);
printf("Client received msg from client  %s",buff);
n++;
}
//close client side connection
close(sockfd);
return(0);
}

GM LAB-COLOR MODEL


Algorithm:

1. Start the program.
2. Declare the variables using structure.
3. Create the function and get the function using create () function.
4. Get the coordinates and assign the values for the coordinates.
5. Define the drawcube () function.
6. Using rotate () function, rotation is performed.
7. End the program.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
int i,j,a,b,c,d,p,q,r,s;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\n enter the color coordinates in RGB:");
scanf("%d%d%d%d",&p,&q,&r,&s);
a=1-p;
b=1-q;
c=1-r;
d=1-s;
i=(8*p)+(4*q)+(2*r)+(1*s);
if(i==0||i==1)
{
i= (8*a)+(4*b)+(2*c)+(1*d);
}
else
{ i=(4*b)+(2*c)+(1*d);
}
outtextxy(100,50,"RGB COLOR IS:");
setcolor(i);
outtextxy(100,100,"(RGB)");
setcolor(6);
delay(400);
setcolor(j);
printf("\nCMY COLOR is:");
outtextxy(150,150,"(CMY)");
getch();
closegraph();
}


MORE:

->GIVE ADS
->EARN MONY
->DOWNLOADS(softwares,wallpapers,etc)
JOB VIRUS