Showing posts with label COMPLIER LAB. Show all posts
Showing posts with label COMPLIER LAB. Show all posts

Tuesday, 25 March 2014

SHIFT REDUCE PARSER

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-SHIFT REDUCE PARSER*/


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>

char ip_sym[15],stack[15];
int ip_ptr=0,st_ptr=0,len,i;
char temp[2],temp2[2];
char act[15];
void check();
int main()
{
printf("\n\t\t SHIFT REDUCE PARSER\n");
printf("\n GRAMMER\n");
printf("\n E->E+E\n ");
printf("\n E->E*E\n E->a");
printf("\n enter the input symbol:\t");
gets(ip_sym);
printf("\n\t stack implementation table");
printf("\n stack\t\t input symbol\t\t action");
printf("\n______\t\t ____________\t\t ______\n");
printf("\n $\t\t%s$\t\t\t--",ip_sym);
strcpy(act,"shift  ");
temp[0]=ip_sym[ip_ptr];
temp[1]='\0';
strcat(act,temp);
len=strlen(ip_sym);
for(i=0;i<=len-1;i++)
{
stack[st_ptr]=ip_sym[ip_ptr];
stack[st_ptr+1]='\0';
ip_sym[ip_ptr]=' ';
ip_ptr++;
printf("\n $%s\t\t%s$\t\t\t%s",stack,ip_sym,act);
strcpy(act,"shift ");
temp[0]=ip_sym[ip_ptr];
temp[1]='\0';
strcat(act,temp);
check();
st_ptr++;
}
st_ptr++;
check();
}
void check()
{
int flag=0;
temp2[0]=stack[st_ptr];
temp2[1]='\0';
if((!strcmpi(temp2,"a")))
{
stack[st_ptr]='E';
if(!strcmpi(temp2,"a"))
printf("\n $%s\t\t%s$\t\t\tE->a",stack, ip_sym);
flag=1;
}
if((!strcmpi(temp2,"+"))||(strcmpi(temp2,"*")))
{
flag=1;
}
if((!strcmpi(stack,"E*E"))||(!strcmpi(stack,"E+E")))
{
strcpy(stack,"E");
st_ptr=0;
if(!strcmpi(stack,"E+E"))
printf("\n $%s\t\t%s$\t\t\tE->E+E",stack,ip_sym);
if(!strcmpi(stack,"E*E"))
printf("\n $%s\t\t%s$\t\t\tE->E*E",stack,ip_sym);
flag=1;
}

if(!strcmpi(stack,"E")&& ip_ptr ==len)
{
 printf("\n $%s\t\t%s$\t\t\tACCEPT",stack,ip_sym);
getch();
 exit(0);
}
if(flag==0)
{
 printf("\n%s\t\t\t%s\t\t reject",stack,ip_sym);
 exit(0);
}
return;
}

THREE ADDRESS CODE

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO GENERATE THREE ADDRESS CODE*/

#include<stdio.h>
#include<string.h>
void pm();
void plus();
void div();
int i,ch,j,l,addr=100;
char ex[10],exp[10],exp1[10],exp2[10],id1[5],op[5],id2[5];
void main()
{
clrscr();
while(1)
{
printf("\n1.assignment\n2.arithmetic\n3.relational\n4.Exit\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the expression with assignment operator:");
scanf("%s",exp);
l=strlen(exp);
exp2[0]='\0';
i=0;
while(exp[i]!='=')
{
i++;
}
strncat(exp2,exp,i);
strrev(exp);
exp1[0]='\0';
strncat(exp1,exp,l-(i+1));
strrev(exp1);
printf("Three address code:\ntemp=%s\n%s=temp\n",exp1,exp2);
break;

case 2:
printf("\nEnter the expression with arithmetic operator:");
scanf("%s",ex);
strcpy(exp,ex);
l=strlen(exp);
exp1[0]='\0';

for(i=0;i<l;i++)
{
if(exp[i]=='+'||exp[i]=='-')
{
if(exp[i+2]=='/'||exp[i+2]=='*')
{
pm();
break;
}
else
{
plus();
break;
}
}
else if(exp[i]=='/'||exp[i]=='*')
{
div();
break;
}
}
break;

case 3:
printf("Enter the expression with relational operator");
scanf("%s%s%s",&id1,&op,&id2);
if(((strcmp(op,"<")==0)||(strcmp(op,">")==0)||(strcmp(op,"<=")==0)||(strcmp(op,">=")==0)||(strcmp(op,"==")==0)||(strcmp(op,"!=")==0))==0)
printf("Expression is error");
else
{
printf("\n%d\tif %s%s%s goto %d",addr,id1,op,id2,addr+3);
addr++;
printf("\n%d\t T:=0",addr);
addr++;
printf("\n%d\t goto %d",addr,addr+2);
addr++;
printf("\n%d\t T:=1",addr);
}
break;
case 4:
exit(0);
}
}
}
void pm()
{
strrev(exp);
j=l-i-1;
strncat(exp1,exp,j);
strrev(exp1);
printf("Three address code:\ntemp=%s\ntemp1=%c%ctemp\n",exp1,exp[j+1],exp[j]);
}
void div()
{
strncat(exp1,exp,i+2);
printf("Three address code:\ntemp=%s\ntemp1=temp%c%c\n",exp1,exp[i+2],exp[i+3]);
}
void plus()
{
strncat(exp1,exp,i+2);
printf("Three address code:\ntemp=%s\ntemp1=temp%c%c\n",exp1,exp[i+2],exp[i+3]);
}


/*OUTPUT
Example Generation of Three Address Project Output Result

1. assignment
2. arithmetic
3. relational
4. Exit
Enter the choice:1
Enter the expression with assignment operator:
a=b
Three address code:
temp=b
a=temp

1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:2
Enter the expression with arithmetic operator:
a+b-c
Three address code:
temp=a+b
temp1=temp-c

1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:2
Enter the expression with arithmetic operator:
a-b/c
Three address code:
temp=b/c
temp1=a-temp

1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:2
Enter the expression with arithmetic operator:
a*b-c
Three address code:
temp=a*b
temp1=temp-c

1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:2
Enter the expression with arithmetic operator:a/b*c
Three address code:
temp=a/b
temp1=temp*c
1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:3
Enter the expression with relational operator
a
<=
b

100 if a<=b goto 103
101 T:=0
102 goto 104
103 T:=1

1.assignment
2.arithmetic
3.relational
4.Exit
Enter the choice:4

*/

Sunday, 23 March 2014

PREDICTIVE PARSER PROGRAM

/*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-STACK IMPLEMENTATION OF PREDICTIVE PARSER*/

#include<ctype.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define non_term_count 5
#define term_count 6
#define rightHandMarker term_count-1
#define no_of_production 8

char nt[]={'E','A','T','B','F'},ter[]={'i','+','*','(',')','$'};
char arr[20][20][20]={
   {"TA","","","TA","",""},
    {"","+TA","","","@","@"},
    {"FB","","","FB","",""},
    {"","@","*FB","","@","@"},
    {"i","","","(E)","",""}
};
char ipstr[20];
char stack[40],prod[10];
int i=0,top=1,ia,ix;

struct predictive_table
{
 char prod[10];
}table[non_term_count][term_count]={"\0"};

struct
{
 int isNull;
 char term[10];
}first[non_term_count]={{0,"(i"},{1,"+"},{0,"(i"},{1,"*"},{0,"(i"}};
struct
{
 int isMarker;
 char term[10];
}follow[non_term_count]={{1,")"},{1,")"},{1,"+)"},{1,"+)"},{1,"+*)"}};
char terminals[term_count-1][2]={"i","+","*","(",")"};
char nonTerminals[non_term_count][3]={"E","A","T","B","F"};
char grammar[no_of_production][10]={"E T A","A + T A","A @","T F B","B * F B","B @","F ( E )","F i"};
char pgrammar[no_of_production][10]={"E->TA","A->+TA","A->@","T->FB","B->*FB","B->@","F->(E)","F->i"};

int matchTerminals(char term[])
{
 int i=-1;
 for(i=0; i<term_count-1; i++)
if(!strcmp(term,terminals[i]))
break;
 return i;
}

void copy_follow(int index,int loc)
{
 char term[2];
 int j,ind;
 if(follow[index].isMarker==1)
 {
  if(strlen(table[index][rightHandMarker].prod)==0)
   strcpy(table[index][rightHandMarker].prod,pgrammar[loc]);
  else
   printf("\nGiven Grammar is not LL(1)");
 }
 j=0;

 while(follow[index].term[j]!='\0')
 {
  term[0]=follow[index].term[j];
  term[1]='\0';
  ind = matchTerminals(term);
  if(strlen(table[index][ind].prod)==0)
   strcpy(table[index][ind].prod,pgrammar[loc]);
  else
   printf("\nGiven Grammar is not LL(1)");
  j++;
 }
}

int matchNonTerminals(char non_term[])
{
 int i=-1;
 for(i=0; i<non_term_count; i++)
if(!strcmp(non_term,nonTerminals[i]))
break;
 return i;
}



void show_table()
{
 int k,i,j;
 printf("\n\t\t\tPredictive Parser Table \n\n");
 printf("   |");
 for(i=0; i<term_count-1; i++)
  printf("    %s    |",terminals[i]);
 printf("    $    |");
 for(i=0; i<non_term_count; i++)
 {
  printf("\n----------------------------------------------------------------");
  printf("\n%s",nonTerminals[i]);
  for(k=strlen(nonTerminals[i]); k<3; k++)
   printf(" ");
  printf("|");
  for(j=0; j<term_count; j++)
  {
    printf(" %s",table[i][j].prod);
    for(k=strlen(table[i][j].prod); k<8; k++)
     printf(" ");
    printf("|");
  }
 }
}
void fun();
int main()
{
 int i,k,j,t,flag=0,indexTerm,indexNonTerm,index;
 char nextChar[10]="\0",nonterm[10]="\0",term[10]="\0";
 for(i=0; i<no_of_production; i++)
 {
  t=0;
  j=0;
  flag=0;
  while(grammar[i][j]!=' '&&grammar[i][j]!='\0')
   nonterm[t++]=grammar[i][j++];
  nonterm[t]='\0';
  indexNonTerm=matchNonTerminals(nonterm);
X:  j++;
  t=0;
  while(grammar[i][j]!=' '&&grammar[i][j]!='\0')
   nextChar[t++]=grammar[i][j++];
  nextChar[t]='\0';
  if(!strcmp(nextChar,"@"))
   copy_follow(indexNonTerm,i);
  else
  {
   index=matchTerminals(nextChar);
   if(index!=term_count-1)
   {
    if(strlen(table[indexNonTerm][index].prod)==0)
     strcpy(table[indexNonTerm][index].prod,pgrammar[i]);
    else
    {
      printf("\nGiven Grammar is not LL(1)");
      break;
    }
   }
   else
   {
    index=matchNonTerminals(nextChar);
    if(index!=non_term_count)
    {
     k=0;
     while(first[index].term[k]!='\0')
     {
       term[0]=first[index].term[k];
       term[1]='\0';
       indexTerm=matchTerminals(term);
       if(strlen(table[indexNonTerm][indexTerm].prod)==0)
strcpy(table[indexNonTerm][indexTerm].prod,pgrammar[i]);
       else
       {
printf("\n Given Grammar is not LL(1) ");
break;
       }
       k++;
     } //end while
     if(first[index].isNull==1)
     {
       flag=1;
       goto X;
     }
     else
      flag=0;
    }
   }
  }
  if(flag==1)
   copy_follow(indexNonTerm,i);
 }
 show_table();
 fun();
 getch();
}


void fun()
{

       void pop();
void push(char);
int resolve_nt(char);
int resolve_t(char);
void advance();
char a,x;
int len,k;
stack[0]='$';
stack[1]='E';
printf("\nenter the input string:\n");
scanf("%s",ipstr);
printf("I/p string\t\tStack\t\tProduction Used\n");
while(1)
{
a=ipstr[i];
x=stack[top];
for(k=i;ipstr[k]!='$';k++)
printf("%c",ipstr[k]);
printf("$\t\t");
if(x==a)
{
if(x=='$')
{
printf("input is accepted");
break;
}
else
{
pop();
advance();
}
}
else if(isupper(x))
{
ix=resolve_nt(x);
ia=resolve_t(a);
strcpy(prod,arr[ix][ia]);
len=strlen(prod);
pop();
for(k=1;k<=len;k++)
push(prod[len-k]);
if(stack[top]=='@')
pop();
}
else
{
printf("error");
break;
}
for(k=0;k<=top;k++)
printf("%c",stack[k]);
printf("\t\t\t%s\n",prod);
}
}

void push(char t)
{
top+=1;
stack[top]=t;
}
void pop()
{
top--;
}
void advance()
{
i++;
}
int resolve_nt(char t)
{
int k,index;
for(k=0;k<5;k++)
{
if(t==nt[k])
{
index=k;
break;
}
}
return index;
}

int resolve_t(char t)
{
int k,index;
for(k=0;k<6;k++)
{
if(t==ter[k])
{
index=k;
break;
}
}
return index;
}

/*OUTPUT


                        Predictive Parser Table

   |    i    |    +    |    *    |    (    |    )    |    $    |
----------------------------------------------------------------
E  | E->TA   |         |         | E->TA   |         |         |
----------------------------------------------------------------
A  |         | A->+TA  |         |         | A->@    | A->@    |
----------------------------------------------------------------
T  | T->FB   |         |         | T->FB   |         |         |
----------------------------------------------------------------
B  |         | B->@    | B->*FB  |         | B->@    | B->@    |
----------------------------------------------------------------
F  | F->i    |         |         | F->(E)  |         |         |
enter the input string:
i+i*i$
I/p string              Stack           Production Used
i+i*i$          $AT                     TA
i+i*i$          $ABF                    FB
i+i*i$          $ABi                    i
i+i*i$          $AB                     i
+i*i$           $A                      @
+i*i$           $AT+                    +TA
+i*i$           $AT                     +TA
i*i$            $ABF                    FB
i*i$            $ABi                    i
i*i$            $AB                     i
*i$             $ABF*                   *FB
*i$             $ABF                    *FB
i$              $ABi                    i
i$              $AB                     i
$               $A                      @
$               $                       @
$               input is accepted

*/

FIRST AND FOLLOW PROGRAM

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO FIND FIRST AND FOLLOW*/

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>

void follow(char c);
void first_1(char c);
void FIRST(char );

int n,m=0,p,i=0,j=0;
char a[10][10],f[10];
int count,n1=0;
char  first[10];

int main()
{
 int i,z,choice;
 char c,ch;
 printf("Enter the no.of productions:");
 scanf("%d",&n);
 printf("Enter the productions(epsilon=$):\n");
 for(i=0;i<n;i++)
  scanf("%s%c",a[i],&ch);
count=n;

do
{
n1=0;
printf("Element :");
scanf("%c",&c);
FIRST(c);
printf("\n FIRST(%c)= { ",c);
for(i=0;i<n1;i++)
printf("%c ",first[i]);
printf("}\n");

printf("press 1 to continue : ");
scanf("%d%c",&choice,&ch);
}
while(choice==1);

 do
 {
  m=0;
  printf("Enter the element whose FOLLOW is to be found:");

  scanf("%c",&c);
  follow(c);
    printf("FOLLOW(%c) = { ",c);
  for(i=0;i<m;i++)
   printf("%c ",f[i]);
  printf(" }\n");
    printf("Do you want to continue(0/1)?");
  scanf("%d%c",&z,&ch);
 }
 while(z==1);
}

void follow(char c)
{

 if(a[0][0]==c)
 f[m++]='$';
 for(i=0;i<n;i++)
 {
  for(j=2;j<strlen(a[i]);j++)
  {
   if(a[i][j]==c)
   {
    if(a[i][j+1]!='\0')
     first_1(a[i][j+1]);

    if(a[i][j+1]=='\0'&&c!=a[i][0])
     follow(a[i][0]);

   }
  }
 }
}
void first_1(char c)
{
      int k;
                 if(!(isupper(c)))
                 f[m++]=c;

                 for(k=0;k<n;k++)
                 {
                 if(a[k][0]==c)
                 {
                 if(a[k][2]=='$')
                  follow(a[i][0]);
                 else if(islower(a[k][2]))
                 f[m++]=a[k][2];

                 else
                  first_1(a[k][2]);
                 }
                 }

}



void FIRST(char c)
{
int j;
if(!(isupper(c)))first[n1++]=c;
for(j=0;j<count;j++)
{
if(a[j][0]==c)
{
if(a[j][2]=='$') first[n1++]='$';
else if(islower(a[j][2]))first[n1++]=a[j][2];
else FIRST(a[j][2]);
}
}
}

/*OUTPUT

Enter the no.of productions:8
Enter the productions(epsilon=$):
E=TD
D=+TD
D=$
T=FS
S=*FS
S=$
F=(E)
F=a
Element :E
FIRST(E)= { ( a }
press 1 to continue : 1

Element :D
FIRST(D)= { + $ }
press 1 to continue : 1

Element :T
FIRST(T)= { ( a }
press 1 to continue : 1

Element :S
FIRST(S)= { * $ }
press 1 to continue : 1

Element :F
FIRST(F)= { ( a }
press 1 to continue : 0

Enter the element whose FOLLOW is to be found:E
FOLLOW(E) = { $ )  }
Do you want to continue(0/1)?1

Enter the element whose FOLLOW is to be found:D
FOLLOW(D) = { $ )  }
Do you want to continue(0/1)?1

Enter the element whose FOLLOW is to be found:T
FOLLOW(T) = { + $ )  }
Do you want to continue(0/1)?1

Enter the element whose FOLLOW is to be found:S
FOLLOW(S) = { + $ )  }
Do you want to continue(0/1)?1

Enter the element whose FOLLOW is to be found:F
FOLLOW(F) = { * + $ )  }
Do you want to continue(0/1)?0 */

Friday, 21 March 2014

LEXICAL TOOL PROGRAM IN C

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-LEXICAL ANALYSIS PROGRAM IN C*/

/*4 FILES ARE NEEDED FOR THIS PROGRAM
1.LEX.C
2.INTER.C-automatically generated on running
3.OPER.C-contains opeartors
4.KEY.C-contains keyword
and one file to perform lexical analysis
NOTE-PUT ALL THREE C FILES IN A SAME FOLDER AND ON RUNNING THE PROGRAM ENTER ANY FILE NAME,THAT SHOULD BE PRESENT IN SAME FOLDER*/

*/


1 LEX.C

#include"stdio.h"
#include"conio.h"
#include<string.h>
#include<ctype.h>

void main()
{
FILE *fi,*fo,*fop,*fk;
int flag=0,i=1;
char c,t,a[15],ch[15],file[20];
clrscr();
printf("Enter the file name : ");
scanf("%s",file);
fi=fopen(file,"r");
fo=fopen("inter.c","w");
fop=fopen("oper.c","r");
fk=fopen("key.c","r");
c=getc(fi);
while(!feof(fi))
{
if(isalpha(c)||isdigit(c)||(c=='['||c==']'||c=='.'==1))
fputc(c,fo);
else
{
if(c=='\n')
fprintf(fo,"\t$\t");
else
fprintf(fo,"\t%c\t",c);
}
c=getc(fi);
}
fclose(fi);
fclose(fo);
fi=fopen("inter.c","r");
printf("\t\tLEXICAL ANALYSIS \n");
fscanf(fi,"%s",a);
printf("\nline : %d\n",i++);
while(!feof(fi))
{
if((strcmp(a,"$")==0))
{
printf("\nline : %d\n",i++);
fscanf(fi,"%s",a);
}
fscanf(fop,"%s",ch);
while(!feof(fop))
{
if(strcmp(ch,a)==0)
{
fscanf(fop,"%s",ch);
printf("\t\t%s\t:\t%s\n",a,ch);
flag=1;
}
fscanf(fop,"%s",ch);
}
rewind(fop);
fscanf(fk,"%s",ch);
while(!feof(fk))
{
if(strcmp(ch,a)==0)
{
fscanf(fk,"%s",ch);
printf("\t\t%s\t:\tkeyword\n",a);
flag=1;
}
fscanf(fk,"%s",ch);
}
rewind(fk);
if(flag==0)
{
if(isdigit(a[0]))
printf("\t\t%s\t:\tconstant\n",a);
else
printf("\t\t%s\t:\tidentifier\n",a);

}
flag=0;
fscanf(fi,"%s",a);
}
getch();
}

------------------------------------------------------------------------------------------------------------

2.key.c

int
void
main
char
if
for
while
else
printf
scanf
FILE
include
stdio.h
conio.h
iostream.h

------------------------------------------------------------------------------------------------------------

3.oper.c

( openpara
) closepara
{ openbrace
} closebrace
<     lesser
> greater
" doublequote
' singlequote
: colon
; semicolon
# preprocessor
= equal
== assign
% percentage
^ bitwise
& reference
* star
+ add
- sub
\ backslash
/ slash


------------------------------------------------------------------------------------------------------------
/*sample file is cd4.c

#include<stdio.h>
#include<conio.h>

int main()
{
int a;
printf("hello");
if(a==1)
{
printf("ok");
}
else
{
printf("notok");
}
}
*/

/*output-

Enter the file name : cd4.c
                LEXICAL ANALYSIS

line : 1
                #       :       preprocessor
                include :       keyword
                <       :       lesser
                stdio.h :       keyword
                >       :       greater

line : 2
                #       :       preprocessor
                include :       keyword
                <       :       lesser
                conio.h :       keyword
                >       :       greater

line : 3
                $       :       identifier
                int     :       keyword
                main    :       keyword
                (       :       openpara
                )       :       closepara

line : 4
                {       :       openbrace

line : 5
                int     :       keyword
                a       :       identifier
                ;       :       semicolon

line : 6
                printf  :       keyword
                (       :       openpara
                "       :       doublequote
                hello   :       identifier
                "       :       doublequote
                )       :       closepara
                ;       :       semicolon

line : 7
                if      :       keyword
                (       :       openpara
                a       :       identifier
                =       :       equal
                =       :       equal
                1       :       constant
                )       :       closepara

line : 8
                {       :       openbrace

line : 9
                printf  :       keyword
                (       :       openpara
                "       :       doublequote
                ok      :       identifier
                "       :       doublequote
                )       :       closepara
                ;       :       semicolon

line : 10
                }       :       closebrace

line : 11
                else    :       keyword

line : 12
                {       :       openbrace

line : 13
                printf  :       keyword
                (       :       openpara
                "       :       doublequote
                notok   :       identifier
                "       :       doublequote
                )       :       closepara
                ;       :       semicolon

line : 14
                }       :       closebrace

line : 15
                }       :       closebrace

line : 16
                $       :       identifier
*/

INFIX TO POSTFIX PROGRAM IN C

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-INFIX TO POSTFIX PROGRAM IN C*/


#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 10

char stack[size];
int tos=0,element;
void push(int element);
char pop();
void show();
int isempty();
int isfull();
char infix[30],output[30];
int prec(char);

int main()
{
        int i=0,j=0,k=0,length;
        char temp;
        printf("enter the infix expression\n");
        scanf("%s",infix);
        length=strlen(infix);
  for(i=0;i<length;i++)
  {
  if(infix[i]!='+' && infix[i]!='-' && infix[i]!='*' && infix[i]!='/' && infix[i]!='^' && infix[i]!=')' && infix[i]!='(' )
    {
   output[j++]=infix[i];
    }
   else
    {
    if(tos==0)
    {
    push(infix[i]);
    }
    else
    {
    if(infix[i]!=')' && infix[i]!='(')
    {
    if( prec(infix[i]) <= prec(stack[tos-1])  )
    {
    output[j++]=pop();
    push(infix[i]);
    }
    else
    {
    push(infix[i]);
    } }
    else
    {
    if(infix[i]=='(')
    {push(infix[i]);}
    if(infix[i]==')')
    {
    temp=pop();
    while(temp!='(')
    {output[j++]=temp;
    temp=pop();}
    }}}}}
    while(tos!=0)
    {
    output[j++]=pop();
    }
 printf("the postfix expression is: %s\n",output);}

void push(int element)
{
    stack[tos]=element;
    tos++;
}
char pop()
{
    tos--;
    return(stack[tos]);
}

int prec(char symbol)
{
if(symbol== '(')
return 0;
if(symbol== ')')
return 0;
if(symbol=='+' || symbol=='-')
return 1;
if(symbol=='*' || symbol=='/')
return 2;
if(symbol=='^')
return 3;
return 0;
}