[antlr-interest] ANTLR Examples - StdCParser for C]
Ric Klaren
klaren at cs.utwente.nl
Thu Oct 4 02:56:22 PDT 2001
Hi,
(It seems this didn't make it to the list in my first attempt)
On Wed, Oct 03, 2001 at 09:09:02PM +0100, David Wigg wrote:
> We are trying to convert the example StdCParser.g to produce C++ code
> instead of Java code.
Are you also thinking of releasing this to the community ? (as an aside
note?)
> At the moment we cannot compile our new CToken.cpp because we are left with
> one compiler error on the return statement from the toString() method which
> states that it cannot add two addresses together [return "CToken:" + "(" +
> etc.]. This would appear to be due to the compiler not being able to access
> the definition of a suitable "operator+"(?).
You probably need to operator+ for int's to std strings in antlr/String.hpp
public String toString() {
return "CToken:" +"(" + hashCode() + ")" + "[" + getType() + "] "+ getText() + " line:" + getLine() + " source:" + source ;
}
Think this should work (untested) if you include String.hpp a little bit
depending on your choices for the return of hashCode.
std::string toString( void )
{
std::string ret("CToken:")
ret += "(" + hashCode() + ")" + "[" + getType() + "] "+ getText() + " line:" + getLine() + " source:" + source ;
}
Other solutions might use a ostringstream but probably a bit slower
although.. with this amount of operator+ calls it might be faster.
{
std::ostringstream ret;
ret << "Ctoken:(" << hashCode()
<< ")[" << getType() << "] " << getText()
<< " line:" << getLine() << " source:" << source ;
return ret.str();
}
It may even be that you need not implement this function since it's usually
a java-ism.
> If anyone would like to see our code for CToken.cpp and CToken.hpp I
> will of course be pleased to send them a copy, but we have checked it
> line by line against CommonToken.cpp and CommonToken.hpp and cannot see
> any significant difference.
If the problem persists send it along and I might have a look at it if I
have a few spare mins.
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
Time what is time - I wish I knew how to tell You why - It hurts to know -
Aren't we machines - Time what is time - Unlock the door
- And see the truth - Then time is time again
From: 'Time what is Time' by Blind Guardian
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list