convert infix to postfix

Need 3 files to complete a program to convert infix math notation to postfix. Need a calculator.cpp,queue_ch.cpp & a main function to test the program. Have sent via e-mail 7 additional files that should go with the 3 needed above.see e-mail sent from Dst6809343@aol on 1/23.Can use the test.cpp file as a model for main function. Thank you for your assistance
Dks3504Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
KangaRooConnect With a Mentor Commented:
/*
                                                
// Begin of File // ******************************************

                        Infix.C

Simple Infix Expression Grammar:

      primairy_expression:
            literal
            (expression)

      multiplicative_expression:
            primairy_expression
            multiplicative_expression * primairy_expression
            multiplicative_expression / primairy_expression
            multiplicative_expression % primairy_expression

      additive_expression:
            multiplicative_expression
            additive_expression + multiplicative_expression
            additive_expression - multiplicative_expression

   This grammar is easily and directly translated into a program. It only
   parses additive (+ and -) and multiplicative (*, / and%) expressions to
   demonstrate implementation of precedence. Other operators and their
   precedence can easily be added.

   Note:      Postfix output is obtained by replacing the printf() statements
               that are followed by a comment saying push...
               with pushes onto the postfix expression (rpn) stack.
*/

#include <stdio.h>
#include <ctype.h>
#include <assert.h>

void  Error(char*);
char* SkipWhite(char*);
int   ParseInfixExpression(char*);
char* AdditiveExpression(char*);
char* MultiplicativeExpression(char*);
char* PrimairyExpression(char*);
char* LiteralExpression(char*);

void Error(char* msg)
{
      assert(msg != 0);
      printf("Error: %s\n", msg);
}

char* SkipWhite(char* expression)
{
      while(expression && isspace(*expression)) ++expression;
   return expression;
}

int ParseInfixExpression(char* expression)
{
      assert(expression != 0);
      expression = AdditiveExpression(expression);
      return !expression || (expression && *expression) ? 0 : 1;
}


char* AdditiveExpression(char* expression)
{
      assert(expression != 0);

      /*      multiplicative_expression */
        expression = SkipWhite(MultiplicativeExpression(expression));

      /*      additive_expression + multiplicative_expression */
      while(expression && (*expression == '+' || *expression == '-'))
      {
            char* tmp = MultiplicativeExpression(expression+1);
      if(tmp) printf("operator: %c\n", *expression); // push operator
      expression = SkipWhite(tmp);
   }
      return expression;
}

char* MultiplicativeExpression(char* expression)
{
      assert(expression != 0);

        expression = SkipWhite( PrimairyExpression(expression) );
      while( expression
                && ( *expression == '*' || *expression == '/' || *expression == '%')
        )
      {
            char* tmp = PrimairyExpression(expression + 1);
      if(tmp) printf("operator: %c\n", *expression); // push operator
      expression = SkipWhite(tmp);
   }
      return expression;
}

char* PrimairyExpression( char* expression )
{
      assert(expression != 0);
      expression = SkipWhite(expression);
      if(*expression == '(')
      {
            expression = SkipWhite(AdditiveExpression(expression+1));
            if(!expression)
            return expression;
      else if(expression && *expression != ')')
            Error("Missing ')' in expression");
            else ++expression; // skip the brace
      }
      else
            expression = LiteralExpression(expression);
      return expression;
}

char* LiteralExpression(char* expression)
{
   int cursor = 0;
      assert(expression != 0);
   expression = SkipWhite(expression);

      while( isalnum(expression[cursor]) ) ++cursor;
   if(cursor)
      {
            char tmp = expression[cursor];
      expression[cursor] = '\0';
      printf("operand:  %s\n", expression); // push operand
      expression[cursor] = tmp;
         return expression + cursor;
   }
   else
   {
         Error("Bad Literal Expression");
            return 0;
   }
}

// End of File // *********************************************

0
 
Dks3504Author Commented:
notify how i can purchase additional points.
0
 
nietodCommented:
We cannot provide answers to school assignments.  That is grounds for removal from this site.  (for both you and the experts involved.)  We can provide only limitied help in accademic assignments.    We can answer specific (direct) questions, like you might ask your teacher.  We can review your work and post suggestions, again, like your teacher might do.

Do you have specific questions?
Do you have any work on this (incomplete even) that we can review?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nietodCommented:
0
 
Dks3504Author Commented:
This is not a school assignment. I resent your threats. You know nothing about the background on this program. I have done a large amount of work on this program. I have already given 200 points to a dominic. I added another 25. I still have not had my question answered. I sent additional files in an effort to provide assistance. If you cannot assist please submit the question to someone else. You may call me if you have a problem with this question at 1-888-467-7549
at 1-888-467-7549.
0
 
nietodCommented:
Sorry, it certainly sounded like a school assignment.  Professional programmers wouldn't usually ask such a question.

If you are asking for help from a particular expert on this (I can't tell if that is the case), then you should put that expert's name in the question.  That will keep other expoerts away.  If you want help form any expert, you will need to supply more information.
0
 
SileNcerCommented:
I have an apqueue.h if your interested...not sure what calculator.cpp is; there is a math.h that will do many kinds of math functions...please be more specific on what you need.
0
 
_Scotch_Commented:
Maybe I'm being naive, and I'm certainly new around here but,
isn't this the kind of thing that a lex-yacc-bison style BNF
grammar is perfect for ?
0
 
Dks3504Author Commented:
To nietod: Thank you for your follow up comments. I hope we can still be friends. Assistance on this program can come from any expert. Thanks also to Silecer & Scotch for your reply to my program. This program is very difficult. That is why I came to experts exchange to obtain assistance from knowlegdeable programmers. That is why I sent 7 files that are part of my work so far. I have already released 200 points to dominic on this program. He provided some answers but without the other header and source files that need to go with program. To respond to Silencer question on calculaor.cpp file. This is the critical file to this program. The header file calculator.h is correct. So the implementation file is what I seek assistance with. If this helps: For the Infix to Postfix conversion process, the Calculator class is designed to have a StackOfChar object to facilitate the process. The class also has a QueueOfChar object for buffering the resulting Postfix expression. In the function to evaluate the Postfix(which is stored in queue), use an object of a StackOfDouble class to facilitate the evaluation process. If you have additional questions please respond. Thank for any assistance.
0
 
ozoCommented:
those of us who haven't seen calculaor.cpp and calculator.h may have some difficulty providing much assistance.
0
 
nietodCommented:
right, that's why I said if you want help from experts other than dominic, you need to supply us with more info.  
0
 
Dks3504Author Commented:
To nietod & ozo: Please read previous e-mails for files that should go with conversion program. These files should be correct with the exception of calculator.cpp and queue_ch.cpp. Have provided some code on these 2 files but is not correct. Will e-mail these 2 files again for your review to qna@experts-exchange.com. To ozo, in my previous comments I attempted to explain the calculator.cpp file. This program uses stacks to pop and push infix notation. Uses calculator.cpp to convert infix notation to postfix and then makes use of queues to store the converted notation. A main function is used to test the program.
0
 
KangaRooCommented:
1) I really wouldn't know how to get to these e-mails. We really need related source files.
2) What exactly do you need help on. Only infix -> prefix conversion.

my mail:
qfm@oce.nl

0
 
KangaRooCommented:
infix -> postfix I mean.
0
All Courses

From novice to tech pro — start learning today.