From: James M. D. <mdu...@ya...> - 2003-03-17 14:11:15
|
--- Stefan Reuther <sr...@ma...> wrote: > whether it fits into its imagination. For example, my "if" > handling code starts with (the equivalent of) > assert(p->First()->Eq("if")); > assert(p->Second()->Eq('(')); > assert(p->Nth(3)->Eq(')')); This is exactly the interface that needs to be rethought to make openc++ more valuable. The current usage of the positions, and the exposure of makes OpenC++ not very reusable. If we have an If object, this should read like this is just a simple class model : class BaseNode {};// the base class of the tree class Token { public : int Eq(const char * pstr){ }; }; // the base class of the leaves class BaseNodeRef { BaseNode * _p; public: BaseNodeRef(BaseNode * p) : _p(p) { }; void assert(int x){ } BaseNode * p() { return _p; } Token * Nth(int p) { return 0;// todo } }; class IfNode : public BaseNodeRef { enum IfValues { OPENCXX_IF_NAME = 1, OPENCXX_IF_OPENPAREN = 2, OPENCXX_IF_CLOSEPAREN = 3 } ; public : IfNode(BaseNode * p) : BaseNodeRef (p) { } void assert() { BaseNodeRef::assert(GetToken()->Eq("if")); BaseNodeRef::assert(GetOpenP()->Eq("(")); BaseNodeRef::assert(GetCloseP()->Eq(")")); } Token * GetToken() { return Nth(OPENCXX_IF_NAME); } Token * GetOpenP() { return Nth(OPENCXX_IF_OPENPAREN); } Token * GetCloseP() { return Nth(OPENCXX_IF_CLOSEPAREN); } }; ===== James Michael DuPont http://introspector.sourceforge.net/ __________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com |