Friday 16 February 2018


Program For identify keywords and Identifiers

#include<stdio.h>
#include<ctype.h>
#include<string.h>
void keyw(char *p);
int i=0,id=0,kw=0,num=0,op=0;
char keys[32][10]={"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto",
"if","int","long","register","return","short","signed",
"sizeof","static","struct","switch","typedef","union",
"unsigned","void","volatile","while"};
main()
{
        char ch,str[25],seps[15]=" \t\n,;(){}[]#\"<>",oper[]="!%^&*-+=~|.<>/?";
        int j;
        char fname[50];
        FILE *f1;
        //clrscr();
printf("enter file path (drive:\\fold\\filename)\n");
scanf("%s",fname);
f1 = fopen(fname,"r");
//f1 = fopen("Input","r");
        if(f1==NULL)
        {
         printf("file not found");
         exit(0);
        }
        while((ch=fgetc(f1))!=EOF)
        {
for(j=0;j<=14;j++)
{
if(ch==oper[j])
{
printf("%c is an operator\n",ch);
op++;
str[i]='\0';
keyw(str);
}
}
for(j=0;j<=14;j++)
{
if(i==-1)
break;
if(ch==seps[j])
{
if(ch=='#')
{
while(ch!='>')
{
printf("%c",ch);
ch=fgetc(f1);
}
printf("%c is a header file\n",ch);
i=-1;
break;
}
if(ch=='"')
{
do
{
ch=fgetc(f1);
printf("%c",ch);
}while(ch!='"');
printf("\b is an argument\n");
i=-1;
break;
}
str[i]='\0';
keyw(str);
}
}
if(i!=-1)
{
str[i]=ch;
i++;
}
else
i=0;
        }
printf("Keywords: %d\nIdentifiers: %d\nOperators: %d\nNumbers: %d\n",kw,id,op,num);
//getch();
}
void keyw(char *p)
{
int k,flag=0;
for(k=0;k<=31;k++)
{
if(strcmp(keys[k],p)==0)
{
printf("%s is a keyword\n",p);
kw++;
flag=1;
break;
}
}
if(flag==0)
{
if(isdigit(p[0]))
{
printf("%s is a number\n",p);
num++;
}
else
{
//if(p[0]!=13&&p[0]!=10)
if(p[0]!='\0')
{
printf("%s is an identifier\n",p);
id++;
}
}
}
i=-1;
}



Output:








CLIENT SERVER CHAT APPLICATION
EXP of parallel distributed system

SERVER


import java.io.*;
import java.net.*;
public class DatagramServer
{
public static void main(String args[])
{
DatagramSocket sock=null;
try
{
sock=new DatagramSocket(7777);
byte[] buffer= new byte[65536];
DatagramPacket incoming=new DatagramPacket(buffer,buffer.length);
echo("server socket created.waiting for incoming data.....");
while(true)
{
sock.receive(incoming);
byte[] data=incoming.getData();
String s =new String(data,0,incoming.getLength());
echo("Server Says OK....Your message is:"+s);
DatagramPacket dp=new DatagramPacket(s.getBytes(),s.getBytes().length,incoming.getAddress(),incoming.getPort());
sock.send(dp);
}
}
catch(IOException e)
{
System.err.println("IOException" +e);
}
}
public static void echo(String msg)
{
System.out.println(msg);
}
}


CLIENT


import java.io.*;

import java.net.*;

import java.util.*;

public class DatagramClient

{

public static void main(String args[])

{

DatagramSocket sock=null;

int port=7777;

String s;

Scanner cin=new Scanner(System.in);

try

{

sock=new DatagramSocket();

InetAddress host=InetAddress.getByName("localhost");

while(true)

{

echo("enter messsage to send");

s=cin.next();

byte[] b=s.getBytes();

DatagramPacket dp=new DatagramPacket(b,b.length,host,port);

sock.send(dp);

byte[] buffer=new byte[65536];

DatagramPacket reply=new DatagramPacket(buffer,buffer.length);

sock.receive(reply);

byte[] data=reply.getData();

s=new String(data ,0,reply.getLength());

}

}

catch(IOException e)

{

System.err.println("IOException" +e);

}

}

public static void echo(String msg)

{

System.out.println(msg);

}

}


OUTPUT:-