ifndef TOKEN_H define TOKEN_H ifdef FLEX define FLEX_SCANNER endif ifndef VALUETYPE define VALUETYPE term endif include <hush/term.h> //#include <hush/string.h> include <iostream.h> include <string.h> // Needs improvement by defining a class string. // A token must have an operator int() to convert // from token to ints when transferring a token and // a value (string) to the parser.
class token : public term { public: //int n; //char* s; char* _news(char* p) { char* x = new char[strlen(p)+1]; strcpy(x,p); term::_hold(0); term::_garbage->_register(x); return x; } public: void _regit() { // term::_hold(this); //AE gives terrible garbage (!) } void msg() { if (n>=0) { //cerr << "CREATING token: " << n << " " << s << endl; } } token() : term(this) { _regit(); n = -1; s = "DUMMY"; msg(); v=0; } token( char* p ) : term(this) { _regit(); n = 0; s = _news(p); msg(); v=0; } token( int i, char* p = "NULL" ) : term(this) { _regit(); n = i; s = _news(p); msg(); } token( int i, char* p , void* x ) { _regit(); n = i; s = _news(p); v = (term*) x; } token(const token& t) : term(this) { _regit(); n=t.n; s=t.s; msg(); } char* str() const { return s; } int no() const { return n; } operator char*() { return s; } // does not work -- C++ 2.0 is buggy operator int() { return n; } //VALUETYPE* v; void print() { cout << "token:" << n << " " << s << "\n"; } };
inline ostream& operator<<(ostream& o, token& t) { o << (char*) t << " "; return o; }
class tokeniter { public: virtual token operator()() = 0; };
endif
Hush Online Technology
hush@cs.vu.nl
11/03/98 |
![]() |
![]() |