#include "token.h" #include #include token::token(token_type t, string s, int v) { type = t; str = s; val = v; } token token::var(string s) { return token(tvariable, s, 0); } token token::num(int v) { return token(tnumber, "", v); } token token::op(string s) { return token(toperator, s, 0); } token token::end() { return token(tend, "", 0); } token_type token::gettype() { return type; } string token::getstring() { return str; } int token::getvalue() { return val; } void token::print() { token_type t = gettype(); if (t == tnumber) cout << "number: " << getvalue() << "\n"; else if (t == tvariable) cout << "variable: " << getstring() << "\n"; else if (t == toperator) cout << "operator: " << getstring() << "\n"; else if (t == tend) cout << "end\n"; else cout << "bad token\n"; }