Oct 9, 2009

Operator precedence parsing algorithm


//This is operator precedence parsing algorithm using C

char pre[10][10],ss[30],rs[30],stk[10][2];
int i,j,k,n,p,sp=0,br=0;
void push();
void pop();
char chk_pre();
void reduce_ss();
void main()
{
clrscr();
strcpy(pre[0]," +*()]");
strcpy(pre[1],"+><<>>");
strcpy(pre[2],"*>><>>");
strcpy(pre[3],"(<<<=e");
strcpy(pre[4],")>>e>>");
strcpy(pre[5],"[<<<e=");
n=6;
scanf ("%s",ss, printf("Enter the source string : "));
strcpy(rs,"[");
strcat(rs,ss);
strcat(rs,"]");
strcpy(ss,rs);
printf("\n");
for(i=0;i<n;i++)
{
for(j=0;j<strlen(pre[i]);j++)
printf("%c\t",pre[i][j]);
printf("\n");}
while(ss[2]!=']' && br==0)
{
sp=0;
for(i=0;i<strlen(ss);i++)
{
if( (ss[i]>='a' && ss[i]<='z') || (ss[i]>='A' && ss[i]<='Z') )
continue;
push();
if(stk[sp-1][1]=='e' || ss[1]==']' || ss[0]==']')
{ printf("\n\nInvalid string.");
br=1;
break; }
if((stk[sp-1][1]=='>' && stk[sp-2][1]=='<') || stk[sp-1][1]=='=')
{ reduce_ss();
pop(); } } }
if(ss[2]==']')
printf("\nValid String.");
getch();
}
void push()
{ stk[sp][0]=ss[i];
stk[sp][1]=chk_pre();
sp++; }
void pop()
{ char tmp,tmp1;
sp--;
tmp=stk[sp][0];
tmp1=stk[sp][1];
sp--;
stk[sp][0]=tmp;
stk[sp][1]=tmp1;
sp++; }
char chk_pre()
{ char tmp;
if(i==0)
tmp=' ';
else
{ for(j=0;j<n;j++)
for(k=0;k<strlen(pre[j]);k++)
if(stk[sp-1][0]==pre[j][0] && stk[sp][0]==pre[0][k])
tmp=(pre[j][k]); }
return tmp; }
void reduce_ss()
{  char t1[30],t3[30];
int tmp;
if(stk[sp-1][0]==')' && stk[sp-2][0]=='(')
tmp=i-2;
else
tmp=i-3;
for(j=0;j<tmp;j++)
{  t1[j]=ss[j];  }
t1[j]='\0';
tmp=tmp+3;
k=0;
for(j=tmp;j<strlen(ss);j++)
{  t3[k]=ss[j];
k++;  }
t3[k]='\0';
strcpy(ss,"");
strcpy(ss,t1);
strcat(ss,"i");
strcat(ss,t3);
}

Sep 17, 2009

Database connection in classic ASP

Dim con
Dim rs
Dim ConnectString
dim accessdb
set con=server.CreateObject("ADODB.Connection")
set rs=server.CreateObject("ADODB.RecordSet")
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\database.mdb"
con.open ConnectString
accessdb="database.mdb"
mysql="select * from table"

rs.open mysql, con, 3, 3

Sep 13, 2009

Advance microprocessor 8086 programs


Arithmetic operation
Practical-1
Aim: Write a program to addition of two numbers.
Software requirements: TASM Simulator
Logic:
assume cs:code,ds:data
data segment
a dw 0001h
b dw 0005h
sum dw ?
data ends
code segment
start: mov ax,data
mov ds,ax
mov ax,a
mov bx,b
add ax,bx
mov sum,ax
mov ah,04ch
int 21h
code ends
end start
Output:

Conclusion:
The program of  addition of two numbers is successfully executed with the use of tasam simulator.
Practical-2
Aim: Write a program to multiply two 16 bit numbers.
Software requirements: TASM Simulator
Logic:
assume cs:code,ds:data
data segment
a dw 0002h
b dw 0005h
multi dw ?
data ends
code segment
start:mov ax,data
mov ds,ax
mov ax,a
mov bx,b
mul bx
mov multi,ax
mov ah,04ch
int 21h
code ends
end start
Output:

Conclusion:
The program of to multiply two 16 bit numbers is successfully executed with the use of tasam simulator.
Practical-3
Aim: Write a program to add and subtract two 4 digit BCD numbers.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
A DB 41H
B DB 29H
SUM DB ?
DIF DB ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AL,A
MOV CL,AL
MOV BL,B
ADD AL,BL
DAA
MOV SUM,AL
MOv AL,CL
SUB AL,BL
DAS
MOV DIF,AL
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of  add and subtract two 4 digit BCD numbers is successfully executed with the use of tasam simulator
Practical-4
Aim: Write a program to find sum of an integer 8-bit array.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
A DB 01H,05H,06H
SUM DB ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV CL,03H
MOV AL,00H
MOV BL,00H
LEA SI,A
AGAIN:
MOV BL,[SI]
ADD AL,BL
INC SI
LOOP AGAIN
DAA
MOV SUM,AL
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of  find sum of an integer 8-bit array is successfully executed with the use of tasam simulator.
Practical-5
Aim: Write a program to count the number of odds and evens from the given 8-bit array.
Software requirements: TASM Simulator
Logic:
assume cs:code,ds:data
data segment
n dw 1001h,8002h,0a003h,0b004h,5505h
d db ?
data ends
code segment
start : mov ax,data
mov ds,ax
mov cl,05h
lea si,n
again : mov ax,[si]
shl ax,1
jnc nocount
inc dl
nocount : inc si
shr ax,1
dec cl
jnz again
mov d,dl
mov ah,04ch
int 21h
code ends
end start
Output:

Conclusion:
The program of count the number of odds and evens from the given 8-bit array is successfully executed with the use of tasam simulator
Practical-6
Aim: Write a program to count the number of 1’s in 16-bit data.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N DW 2306H
O DB ?
DATA ENDS
CODE SEGMENT
START : MOV AX,DATA
MOV DS,AX
MOV AX,N
MOV CL,0FH
MOV DL,00H
AGAIN  :  SHR AX,1
JNC NOCOUNT
INC DL
NOCOUNT :  LOOP AGAIN
MOV O,DL
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of count the number of 1’s in 16-bit data is successfully executed with the use of tasam simulator.
Practical-7
Aim: Write a program to find a factorial of a given number.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N DW 3
ANS DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,0001H
MOV CX,N
AGAIN:
MUL CX
DEC CX
JNZ AGAIN
MOV ANS,AX
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of find a factorial of a given number is successfully executed with the use of tasam simulator.
Practical-8
Aim: Write a program to find factors of the given number.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N Dw 06H
ANS Dw ?
MSG DB '  FACTORS '
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AH,9
LEA DX,MSG
MOV AX,06h
MOV CL,06h
lea di,ans
AGAIN:
mov ax,06h
DIV cl
CMP AH,00H
JZ FCT
DEC CL
JNZ AGAIN
JZ PEND
FCT:
mov [di],cl
inc di
INC BL
DEC CL
JNZ AGAIN
PEND:
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of find factors of the given number is successfully executed with the use of tasam simulator.
Practical-10
Aim: Write a program to find complete Fibonacci series till n th number. 
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N DB 09H
A DB 01H
B DB 00H
MSG DB 'FIBONACCI','     ','SERIES'
SUM DB 01H
ANS DB ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AH,9
LEA DX,MSG
MOV AL,A
MOV BL,B
MOV CL,N
MOV DL,SUM
lea si,ans
AGAIN:
CMP DL,CL
JNC AOUT
ADD AL,BL
CMP AL,CL
JNC AOUT
MOV DL,AL
mov [si],al
inc si
MOV AL,BL
MOV BL,DL
JMP AGAIN
AOUT:
MOV ANS,DL
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of find complete Fibonacci series till n th number is successfully executed with the use of tasam simulator.
Practical-11
Aim: Write a program to find a total number of negative elements in a given array.
Software requirements: TASM Simulator
Logic:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N DW 1001H,8002H,0A003H,0B004H,5505H
D DB ?
DATA ENDS
CODE SEGMENT
START : MOV AX,DATA
MOV DS,AX
MOV CL,05H
LEA SI,N
AGAIN : MOV AX,[SI]
SHL AX,1
JNC NOCOUNT
INC DL
NOCOUNT : INC SI
SHR AX,1
DEC CL
JNZ AGAIN
MOV D,DL
MOV AH,04CH
INT 21H
CODE ENDS
END START
Output:

Conclusion:
The program of find a total number of negative elements in a given array is successfully executed with the use of tasam simulator.

Sep 10, 2009

system programming-quardple


void main()
{
char str[50],b,c,op[20],op1[20],op2[20];
int a=49,i,j,k=1,opi=0,op1i=0,op2i=0;
clrscr();
printf("enter string\n");
gets(str);
while(strlen(str)>=3)
{
i=0;
while(1)
{
if(str[i]>=33&&str[i]<=47)
{
op1[op1i++]=str[i-2];
str[i-2]=a++;
op[opi++]=str[i];
op2[op2i++]=str[i-1];
for(k=i;k<=strlen(str);k++)
str[k]=str[k+1];
str[k]=NULL;
for(k=i-1;k<=strlen(str);k++)
str[k]=str[k+1];
str[k]=NULL;
break;
}
else
{
i++;
}
}
}
op[opi]=NULL;
op1[op1i]=NULL;
op2[op2i]=NULL;
printf("\nTriple no. operator operator1 oprator2\n");
for(i=0;i<strlen(op);i++)
printf("%d\t\t%c\t%c\t%c\n",i+1,op[i],op1[i],op2[i]);
getch();
}

lexical analysis

//copyright this program is made by Jayesh Amin....
//This program is used to perform lexical Analysis....


//function for checking duplicate values

int check(char a[],char x,int z)
{
int y;
for(y=0;y<z;y++)
{
if(a[y]==x)
return 1;
}
return 0;
}

//function for printing lexical analysis

int print(char a[],char x1)
{
int q=0;
while(a[q]!=x1)
{
q++;
}
return q;
}

//main program starts

void main()
{

//variable declaration

int no,i,p,opi=0,keyi=0,idi=0,keyj=0,idp,opp,j,c,keyflag=1;
char stat[10][30],key[50],op[50],id[50],temp;
clrscr();

/* entering statements */

printf("\nHow many statements you want to enter???\n");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("\nenter statement%d\n",i+1);
scanf("%s",stat[i]);
}
clrscr();
printf("\nyour statements are:\n\n");
for(i=0;i<no;i++)
{
printf("%s\n",stat[i]);
}
printf("\n");

//logic of the program starts

printf("your answer of lexical analysis is:\n\n");
for(i=0;i<no;i++)/*loop for no. of statements*/
{
for(j=0;j<strlen(stat[i]);j++)/*loop for statement length*/
{
/*if 1st char is identifier and after that ':' is there then do this*/
if((stat[i][j]>=97 && stat[i][j]<=122) && (stat[i][j+1]==':'))
{

if(check(id,temp,idi)==0)
{
id[idi]=stat[i][j];
idi++;
}
temp=stat[i][j];
idp=print(id,temp);
printf("(id#%d)",idp+1);
j++;
temp=stat[i][j];
if(check(op,temp,opi)==0)
{
op[opi]=stat[i][j];
opi++;
}
opp=print(op,temp);
printf("(op#%d)",opp+1);
j++;
while(stat[i][j]!=';')
{
key[keyi]=stat[i][j];
keyi++;
j++;
}
key[keyi]=' ';
keyi++;
printf("(key#%d)",keyflag);
keyflag++;
temp=stat[i][j];
if(check(op,temp,opi)==0)
{
op[opi]=stat[i][j];
opi++;
}
opp=print(op,temp);
printf("(op#%d)",opp+1);
break;
}

/*if 1st char is identifier and after that ',' is there then do this*/

else if((stat[i][j]>=97 && stat[i][j]<=122) && (stat[i][j+1]==','))
{
if(check(id,temp,idi)==0)
{
id[idi]=stat[i][j];
idi++;
}
temp=stat[i][j];
idp=print(id,temp);
printf("(id#%d)",idp+1);
j++;
temp=stat[i][j];
if(check(op,temp,opi)==0)
{
op[opi]=stat[i][j];
opi++;
}
opp=print(op,temp);
printf("(op#%d)",opp+1);
}

/*if 1st char is identifier and after that '=' is there then do this*/

else if((stat[i][j]>=97 && stat[i][j]<=122) && (stat[i][j+1]=='='))
{
temp=stat[i][j];
idp=print(id,temp);
printf("(id#%d)",idp+1);
j++;
temp=stat[i][j];
if(check(op,temp,opi)==0)
{
op[opi]=stat[i][j];
opi++;
}
opp=print(op,temp);
printf("(op#%d)",opp+1);
j++;
while(stat[i][j]!=';')
{
c=(int)stat[i][j];
if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
{
temp=c;
idp=print(id,temp);
printf("(id#%d)",idp+1);
}
else
{
temp=stat[i][j];
if(check(op,temp,opi)==0)
{
op[opi]=stat[i][j];
opi++;
}
opp=print(op,temp);
printf("(op#%d)",opp+1);
}
j++;
}
temp=stat[i][j];
opp=print(op,temp);
printf("(op#%d)",opp+1);
break;
}
else
{
}
}
printf("\n");
}

op[opi]=NULL;
key[keyi]=NULL;
id[idi]=NULL;

/* To print identifiers,operators and keywords seperately */

printf("\nidentifiers are--->%s\n",id);
printf("\noperators are----->%s\n",op);
printf("\nkeywords are------>%s\n",key);
getch();
}


system programming-teminal and non terminal


void main()
{
/* variable declaration */

int no,i,p,m=0,n=0,j,flag;
char prod[10][20],ts[50],nts[50],c;
ts[0]=NULL,nts[0]=NULL;
clrscr();

/* entering production */

printf("\nhow many production you want to enter\n");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("\nenter production%d\n",i+1);
scanf("%s",prod[i]);
}
for(i=0;i<no;i++)/*loop for no. of productions*/
{
for(j=0;j<strlen(prod[i]);j++)/*loop for production length*/
{
c=prod[i][j];
if(c>=97 && c<=122)/*check for terminal symbols*/
{
for(p=m;p>=0;p--)
{
if(ts[p]==c)
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
{
ts[m]=c;
m++;
}
}
else if(c>=65 && c<=90)/*check for non terminal symbols*/
{
for(p=n;p>=0;p--)
{
if(nts[p]==c)
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
{
nts[n]=c;
n++;
}
}
else
{
}
}
ts[m]=NULL;
nts[n]=NULL;
}

/*display final result*/

printf("\nterminl symbols are %s\n",ts);
printf("\nnon terminal symbols are %s",nts);
getch();
}


siedle method

#include
#include
#include

float ff (float x)
{
return (pow(x,2.0)-12.0);
}

void main()
{
int i=1;
float x1,x2,x3,e,f1,f2,f3;
clrscr();
printf("Enter value of tolerance : ");
scanf("%f",&e);
printf("enter x1 and x2 : ");
scanf("%f%f",&x1,&x2);
do{
printf("\n\n\n----------------------------------------------------");
printf("\n\n\nIteration %d",i);
printf("\n\n\nx1 = %f",x1);
printf("\t x2 = %f",x2);
f1=ff(x1);
f2=ff(x2);


x3=(x1*f2-x2*f1)/(f2-f1);
f3=ff(x3);
x1=x2;
x2=x3;
i++;
}while(fabs(f3)>e);
printf("\n\n\n------------------------------------------------\n\n");
printf("The root is : %f",x3);
getch();
}

jacobi mehod

#include
#include
#include
#include
void main()
{
float a[20][20],b,c,x[20],y[20];
int i,j,k,no,flag;
clrscr();
cout<<"how many eq. u want to enter?\n";
cin>>no;
for(i=1;i<=no;i++)
{
for(j=1;j<=no+1;j++)
{
printf("enter val. of a[%d][%d]",i,j);
cin>>a[i][j];
}
}
cout<<"matrix is\n";
for(i=1;i<=no;i++)
{
for(j=1;j<=no+1;j++)
{
cout<
cout<<"\t";
}
cout<<"\n";
}
for(k=1;k<=no;k++)
y[k]=0.0;
 for( k=1;k<=no;k++)
x[k]=0.0;
for(;;)
{
for(i=1;i<=no;i++)//i start
{
float temp=0.0;
for(j=1;j<=no;j++)
 {
if(i!=j)
{
temp+=a[i][j]*y[j];
x[i]=(a[i][no+1]-temp)/a[i][i];
y[i]=x[i];
}//if ends
 } //j ends
}   //i ends
int n=1;
for(int m=1;m<=no;m++)
{
if(x[m]-y[m]<=0.001)
n++;
}
if(n==no)
break;
}
for(j=1;j<=no;j++)
{
printf("\nx%d is\n",j);
cout<
}
cout<<"\n";
getch();
}

gauss elimination method

#include
#include
#include
void main()
{
int i=0,j=0,k=0,n=0;
float sum,a[100][100],temp,x[50];
clrscr();
printf("Enter the order of matrix : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n+1;j++)
    {
    printf("\nEnter value of a[%d][%d] : ",i,j);
    scanf("%f",&a[i][j]);
    }
}
printf("\n\nEquations are : \n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("\t%f",a[i][j]);
}
printf("\n\n");
}
for(k=1;k<=n-1;k++)
{
for(j=k+1;j<=n;j++)
{
temp=a[j][k]/a[k][k];
for(i=k;i<=n+1;i++)
{
a[j][i]=a[j][i]-(temp)*a[k][i];
}
}
}
printf("\nNew Eq : \n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("\t%f",a[i][j]);
}
printf("\n");
}
x[n]=(a[n][n+1]/a[n][n]);
for(i=n-1;i>=0;i--)
{
sum=0;
for(j=i+1;j<=n;j++)
{
sum=sum+(a[i][j]*x[j]);
}
x[i]=(a[i][n+1]-sum)/a[i][i];
}
printf("\nRoots are : ");
for(i=1;i<=n;i++)
{
printf("\t%f",x[i]);
}
getch();
}