infix to assembler

kalakuttaAsked:
Who is Participating?
 
MoondancerConnect With a Mentor Commented:
80 points refunded, moved to PAQ at zero to close.
Moondancer - EE Moderator
0
 
Andrey_KulikCommented:
you could send yous question by email to moderator...
0
 
kalakuttaAuthor Commented:
how do i contact the moderator
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
kalakuttaAuthor Commented:
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
 
PandoraModCommented:
kalakutta, is this last post your question??

PandoraMod
Moderator @ Experts Exchange
0
 
kalakuttaAuthor Commented:
yes
0
 
jonninCommented:
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
 
MoondancerCommented:
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
 
MoondancerCommented:
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
 
griesshCommented:
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
 
MoondancerCommented:
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
 
jonninCommented:
Refund the points and close the question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.