[antlr-interest] Re: symbol table in C++
Fan Yang
yhhf_dy at yahoo.com
Fri May 30 13:16:05 PDT 2003
Thank you for your help.
> The trick is that Java uses references--each of the cross-
referenced
> items is actually a pointer, but the compiler hides this--and all
> pointers are of fixed size which makes memory allocation easy. To
> do the same thing in C++, you will have to make the references
> explicit--"HashTable& foo" for example instead of "Hashtable foo".
That's exactly what I did. I have used pointer/reference throughout
the new implementation.
> You may also need to declare a forward reference to the class--that
> should just be a line of the form class Hashtable;
I have used forward references in the new implementation. But the
problem is that you can't reference members of the type which is
defined by forward reference. For example, there are compile errors
if you use forward referennce for hashtable or symboltable. The
reason is that JavaHashtable calls SymbolTable.LookupDummy(), and
SymbolTable calls JavaHashtable.get().
The following code snip simplifies the former problem.
class B;
class A{
private:
B*pb;
public:
A(B*b):pb(b){}
void hello(){
pb->hello(); // complie error
}
};
class B{
private:
A*pa;
public:
...
void hello(){
}
}
I know Template can overcome this simple problem. but the symbol
table program is much more complex than above example. I'm not sure
it's a right way to do it. Does there exist some kind of patterns to
deal with conversion from java to c++ code. thanks.
Fan
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list