[antlr-interest] Re: Conversion StdCParser for C++
ramon_casellas
casellas at infres.enst.fr
Tue Feb 5 04:59:55 PST 2002
--- In antlr-interest at y..., David Wigg <wiggjd at s...> wrote:
> Can anyone point me to a C++ equivalent (or near) to java hashtable
> class?
>
Hi (new to the list, sorry if I am being redundant)
I had never worked with grammars before (I am quite new to this), but
a scripting module for a C++ project of mine has forced me to :). I
happened to find antlr, and let me first say thank you to antlr
developers : it is a very good tool, and it fits my needs.
In order to start learning abour lexers, parsers and treewalkers, I
started by porting the tinybasic sample to C++, so I can give you a
piece of advice here: to the best of my knowledge, you can
only "emulate" java hashtable with C++ STL containers. Typically you
would use (as other readers have suggested) std::map or related
extensions (as in SGI, gcc 3.0X boost or even MS VC NET). However you
need to take into account the fact that (I am not a java programmer,
please correct me if I am wrong) java containers are heterogeneous
since java classes have a common "Object" base class. You may need to
have something like an heterogenous container in C++. In that case, I
would strongly suggest either using the "any" class (boost/any.hpp),
or deriving your C++ classes from an abstract base class with the
required virtual methods. Do not store pointers in STL containers,
but rather encapsulate them using shared_ptr (also from boost). The
later is the way I usually implement heterogeneous containers in C++.
Do not store auto_ptrs in STL containers since they are an special
type of smart pointers than transfer ownership on copy.
something like
std:map<std::string /* identifier */, shared_ptr<variable> /* var */>
symboltable;
symboltable["foo"]->set_type(INT_VAR);
symboltable["foo"]->set_value(5);
etc...
may be handy
Hope this helps,
Regards,
Ramon
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list