Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert infix to postfix

Posted on 1999-01-23
14
Medium Priority
?
1,833 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:Dks3504
  • 4
  • 4
  • 3
  • +3
14 Comments
 

Author Comment

by:Dks3504
ID: 1184978
notify how i can purchase additional points.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184979
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
 
LVL 22

Expert Comment

by:nietod
ID: 1184980
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dks3504
ID: 1184981
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
 
LVL 22

Expert Comment

by:nietod
ID: 1184982
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
 

Expert Comment

by:SileNcer
ID: 1184983
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
 
LVL 3

Expert Comment

by:_Scotch_
ID: 1184984
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
 

Author Comment

by:Dks3504
ID: 1184985
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
 
LVL 85

Expert Comment

by:ozo
ID: 1184986
those of us who haven't seen calculaor.cpp and calculator.h may have some difficulty providing much assistance.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184987
right, that's why I said if you want help from experts other than dominic, you need to supply us with more info.  
0
 

Author Comment

by:Dks3504
ID: 1184988
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1184989
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1184990
infix -> postfix I mean.
0
 
LVL 7

Accepted Solution

by:
KangaRoo earned 40 total points
ID: 1184991
/*
                                                
// 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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question