Ejemplo n.º 1
0
void tprime()
{
	int incoming = mulop();
	if(incoming == 1)
	{
		factor();
		tprime();
	}
	else
		return;
}
Ejemplo n.º 2
0
void postfix(char *input){
  int i,valid=TRUE;
  for(i=0;input[i]!='\0'&&valid;i++){
    //printf("%c\n",input[i]);
    //if(input[i]=='0'||input[i]=='1'||input[i]=='2'||input[i]=='3'||input[i]=='4'||input[i]=='5'||input[i]=='6'||input[i]=='7'||input[i]=='8'||input[i]=='9'){
    ////push(start,(int)input[i]);
    //printf("%d",input[i]);    //debug
    //}
    //else if(input[i]=='+'||input[i]=='-'||input[i]=='*'||input[i]=='/'||input[i]=='$'){
    //printf("%c",input[i]);    //debug
    //}
    //else{
    //printf("\nInvalid String !\n");
    //}
    switch(input[i]){
    case '0': push(&(start->top),0); break;
    case '1': push(&(start->top),1); break;
    case '2': push(&(start->top),2); break;
    case '3': push(&(start->top),3); break;
    case '4': push(&(start->top),4); break;
    case '5': push(&(start->top),5); break;
    case '6': push(&(start->top),6); break;
    case '7': push(&(start->top),7); break;
    case '8': push(&(start->top),8); break;
    case '9': push(&(start->top),9); break;
/*
    case '0': push(start,0); break;
    case '1': push(start,1); break;
    case '2': push(start,2); break;
    case '3': push(start,3); break;
    case '4': push(start,4); break;
    case '5': push(start,5); break;
    case '6': push(start,6); break;
    case '7': push(start,7); break;
    case '8': push(start,8); break;
    case '9': push(start,9); break;  
 */  
    case '+': addop(); break;
    case '-': subop(); break;
    case '*': mulop(); break;
    case '/': divop(); break;
    case '$': expop(); break;
    default: printf("\nInvalid String !\n"); valid=FALSE; break;
    }//end switch
  }//end for
  
}
Ejemplo n.º 3
0
int tprime()
{
 if(mulop())
 {
  if(factor())
  {
   if(tprime())
	return 1;
   else
	return 0;
  }
  else
   return 0;
 }
 else
  return 1;
}
Ejemplo n.º 4
0
//*********Main Function**************
int main(){
    int i,valid=TRUE;
    start=getNode();
    start->info=0;
    start->next=NULL;

    printf("\nEnter Postfix String: ");
    gets(input);
    for(i=0;input[i]!='\0'&&valid;i++){
        //printf("%c\n",input[i]);
        //if(input[i]=='0'||input[i]=='1'||input[i]=='2'||input[i]=='3'||input[i]=='4'||input[i]=='5'||input[i]=='6'||input[i]=='7'||input[i]=='8'||input[i]=='9'){
            ////push(start,(int)input[i]);
            //printf("%d",input[i]);    //debug
        //}
        //else if(input[i]=='+'||input[i]=='-'||input[i]=='*'||input[i]=='/'||input[i]=='$'){
            //printf("%c",input[i]);    //debug
        //}
        //else{
            //printf("\nInvalid String !\n");
        //}
        switch(input[i]){
            case '0': push(start,0); break;
            case '1': push(start,1); break;
            case '2': push(start,2); break;
            case '3': push(start,3); break;
            case '4': push(start,4); break;
            case '5': push(start,5); break;
            case '6': push(start,6); break;
            case '7': push(start,7); break;
            case '8': push(start,8); break;
            case '9': push(start,9); break;
            case '+': addop(); break;
            case '-': subop(); break;
            case '*': mulop(); break;
            case '/': divop(); break;
            case '$': expop(); break;
            default: printf("\nInvalid String !\n"); valid=FALSE; break;
        }//end switch
    }//end for
    printf("\nValue of expression %s\t=",input);
    display(start->next);
    printf("\n");
    
}//end main