Solved

infix to assembler

Posted on 2001-07-11
13
431 Views
Last Modified: 2008-03-03
0
Comment
Question by:kalakutta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6274486
you could send yous question by email to moderator...
0
 

Author Comment

by:kalakutta
ID: 6274619
how do i contact the moderator
0
 

Author Comment

by:kalakutta
ID: 6274620
thanks nietod i finally got it to work last night,now    i have to convert it to assembler ie;

Infix Expression: ((A+(B*C))/(D-E))
Postfix Expression: ABC*+DE-/

Opcode Operand Comment
LD B Load in B.
MU C B * C.
ST TEMP1 Save results of B * C.
LD A Load A.
AD TEMP1 Add A to B * C.
ST TEMP2 Save result.
LD D Load D.
SB E D - E.
ST TEMP3 Save result.
LD TEMP2 Get A + B * C.
DV TEMP3 Divide it by D - E.
ST TEMP4 Save result, also still in register.



#include<iostream.h>
#include<stdlib.h>
#include"stack.h"
#include<fstream.h>
void Assembler();
void Convert( );

char infix[20];
char postfix[20];
void open_input_file(ifstream &in)

{
     char name[80];
     cout << "Enter File Name:";
     cin >> name;
     in.open(name);
}


void main()
{
     ifstream in;                           // reads file

     char ch;
     int i=0;
     
     stack stck;
     
     open_input_file(in);    
     while (!in.eof())
     {
          in.get(ch);    
          if (!in.eof())
          {
               cout << ch;
               infix[i]=ch;
               i++;
               
          }
     }

     in.close();
     
     cout << endl << endl;

Convert();
Assembler();

}




void Convert( ) // converts infix to postfix
{
     int i=0;     // index variable
      char op= '\0';  // top element of stack
     stack stck;      // stack
     cout<<"postfix: ";
     
     while ((infix[i] != '\0')&&(!stck.Fullstack()))
     {
     
          if(infix[i]=='(')
          {
               // push '(' onto stck
               stck.Push(infix[i]);
               op = infix[i];          // '(' is the top element of the stack
          }
          else if (infix[i] == ')')
          {
               // po and write all operator until encountering '('
               while ((op != '(') && (!stck.Emptystack()))
               {
                    op = stck.Pop();

                         if (op == '(')
                              stck.Push(op);
                         else
                              cout << op;
               }
               // now pop '('
               op = stck.Pop();
;
               // need to know what the top element of the stack is
               if (!stck.Emptystack())
               {
                    op = stck.Pop();
;
                    stck.Push(op);
               }
               else
                    op = '\0';
          }
          else if ((infix[i] == '*') || ( infix[i] == '/'))
          {
               // pop and write all '*' and '/' operators from the top down
               // to, but not including the top most'(', '+','-', or not to
               // the bottom of the stack

               while((op != '(') && (op != '+')&&
                    (op!='-')&&(!stck.Emptystack()))
               {
                    op = stck.Pop();

                    if((op=='(')||(op=='+')||(op=='-'))
                   
                    stck.Push(op);
               else
                    cout<< op;
     }
          // push new symbol

     stck.Push(infix[i]);
     op = infix[i];
}
else if ((infix[i] == '+') || (infix[i] == '-'))
{
     while((op!='(') && (!stck.Emptystack()))
     {
          op = stck.Pop();

          if (op == '(')
               stck.Push(op);
          else
               cout<<op;
     }

     stck.Push(infix[i]);
     op = infix[i];
}
else if (infix[i] != ' ')

cout<< infix[i];  // write operand

i++;

}
while (!stck.Emptystack())
{
     // pop and write all operators
     if (op != '(')
     op = stck.Pop();

     cout<< op;
}
}

// this is where the assembler function starts

void Assembler()
{
stack stck;
char top;
int i;
int j;
while(infix[i])
{
     cin>>postfix[j];
     i++;
}


while ((postfix[j] != '\0')&&(!stck.Fullstack()))
{
     

if ((postfix[j]=='*')||(!stck.Emptystack()))
               {
                    top = stck.Pop();

                    stck.Push(top);
               }
cout<<top;


}
}

0
Technology Partners: 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!

 

Expert Comment

by:PandoraMod
ID: 6274711
kalakutta, is this last post your question??

PandoraMod
Moderator @ Experts Exchange
0
 

Author Comment

by:kalakutta
ID: 6274783
yes
0
 
LVL 2

Expert Comment

by:jonnin
ID: 6276868
If you are feeling brave, compile it and generate an asm listing. It should have each c++ line expanded into asm. This will have to be cleaned up and optimized, but its a fast start. Else you will have to do it all by hand...

Compilers do tend to use strange asm instructions in strange ways and places.  Lea is a favorite (is this intel?)  
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6727594
kalakutta -------->  Here is your history, which reflects you've asked 16 questions, but only graded/closed 3 of them.  I think you'll agree that asking for help, getting feedback and not closing and awarding questions is not fair to those who help you.  If you need help in splitting question points between experts, or otherwise in terms of special handling, just comment here, please, with details.  If more is needed, please let the experts know.

Please return and update/finalize all your open questions.  If not resolve in one week, we will need to take actions.  I will post this in all your open question, and also ask that you refer to this site's Guidelines and the Member Agreement you signed off on when you joined this site.  They are available here:

http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Your responsiveness and understanding is appreciated.

EXPERTS.... PLEASE provide closing recommendations here, in the event this needs to be resolved by us.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6784510
EXPERTS PLEASE ADVISE ME....

Who should get these points so I can close them, Asker remains unresponsive.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 11

Expert Comment

by:griessh
ID: 6828126
I suggest to refund the points and PAQ. I think jonnin's comment is a good advice but wouldn't accept is as a satisfying answer.


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6851253
ADMINISTRATION WILL BE CONTACTING kalakutta SHORTLY.  This is THIRD REQUEST added to all open questions, then I will return here to finalize this.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20152259.html
http://www.experts-exchange.com/questions/Q.20155521.html
http://www.experts-exchange.com/questions/Q.20166291.html
http://www.experts-exchange.com/questions/Q.20207366.html
http://www.experts-exchange.com/questions/Q.20218527.html
http://www.experts-exchange.com/questions/Q.20224666.html
http://www.experts-exchange.com/questions/Q.20186351.html
http://www.experts-exchange.com/questions/Q.20149349.html
http://www.experts-exchange.com/questions/Q.20271577.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link, entitled EXPERTS WHO ARE TIRED OF ABANDONED QUESTIONS CAN HELP"  ... http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Thank you everyone.
Moondancer
Moderator @ Experts Exchange
P.S.  For any year 2000 questionsspecial attention is needed to ensure the first correct response is awardedsince they are not in the comment date orderbut rather in Member ID order."
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6851319
80 points refunded, moved to PAQ at zero to close.
Moondancer - EE Moderator
0
 
LVL 2

Expert Comment

by:jonnin
ID: 6855195
Refund the points and close the question.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

732 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