Token problems

I'm currently trying to learn about using Tokens in basic programs but having a tough time figuring them out. The book I'm learning from is kind of confusing me in a few aspects. What I need help on is:

1. Is "Grammar" a road map used to see where you want the program to go and how it should read things?
2. This code that I'm posting was pretty much taken from the book and said to work, yet when I try and compile it on Dev C++ I get a few errors.
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
class Token{
      public:
             char kind;
             double value;
              Token(char ch)
                        :kind(ch), value(0){}
             Token(char ch, double val)
                        :kind(ch), value(val){}
};

Token get_token();
vector<Token>tok;

int main()
{
    while(cin){
               Token t=get_token();
               tok.push_back(t);
               }
    for(int i=0; i<tok.size(); ++i){
            if(tok[i].kind=='*'){
                                 double d=tok[i-1].value*tok[i+1].value;
                                 }
            }
            system ("pause");
            return 0;
}
}


Understanding the idea of Tokens and how exactly to implement them is something I need help with. So any type of help would be appreciated.
What book are you using (or what year was it released)?

http://cplusplus.com/articles/36vU7k9E/

Dev-C++ comes with an out-dated compiler, so this may lead to some issues.

What errors do you get?

Is this the full code you tried to compile (do you have the #include files)?

One thing that I notice is that you have an extra end brace ('}') at the end of your program.
Last edited on
Book: Bjarne Stroustrup's Programming: Principles and Practices using C++ (2009)

Errors: After I removed that extra '}' it was a Linker error - undefined reference to 'get_token()' Id return 1 exit status

I'm also using #include "std_lib_facilities.h". My teacher gave us a long code to use as our header that's supposed to include all the necessary stuff.
Bump :>
Topic archived. No new replies allowed.