Tokenizing arithmetical expression and printing it as an assembly operations

Hello everyone. I have to make a compiler that will print out the given expression as a set of assembly operations. I have the following:

As input (string) we have arithmetical expression (only =, +, * and () operands) and as an output it should print the expression in the form of a pseudo-assembler. So far, I've managed to split all the tokens from the string, but have some difficulties with coding the next part. I tried with checking if each token issalpha() or ispunct() and corresponding to that to print what is desired, but still cannot get the right thing (type conversions get in the way). Any suggestions will be welcomed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  /* strtok example */
    #include <string>
    #include <cstdlib>
    #include <vector>
    #include <iostream>
    #include <cctype>
    #include <string>
    using namespace std;
    vector<string> spliter(string& stringToSplit)
        {
        vector<string> result;
        size_t pos = 0, lastPos = 0;
        while ((pos = stringToSplit.find_first_of("=*+ ( ) abcdefghijklmnopqrstuvwyxz", lastPos)) != std::string::npos)
            {
            result.push_back(stringToSplit.substr(lastPos, pos-lastPos+1));
            lastPos = pos+1;
            }
        result.push_back(stringToSplit.substr(lastPos));
        return result;
        }
    void getinput(string *n)
        {
        getline(cin,*n);
        }
    int main ()
        { 
        cout<<"Enter expression:"<<endl;
        string n = "";
        getinput(&n);
        vector<string>a = spliter(n);
        for (int x = 0; x != a.size(); ++x)
            {
                cout << a.at(x)<<endl;      
            }
        for (int x = 0; x != a.size(); ++x)
        {
         //...
        }
        system("pause");
        return 0;
        }


Example of output: http://oi59.tinypic.com/ra1ziq.jpg
Topic archived. No new replies allowed.