Solved

convert infix to postfix

Posted on 1999-01-23
14
1,714 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 84

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 20 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now