[antlr-interest] C++ Map not usable, always SEGFAULT
Christian Benjamin Ries
christian_benjamin.ries at fh-bielefeld.de
Fri Oct 15 02:05:28 PDT 2010
Hello, I'm a little bit frustated.
I'm trying to use a C++ Map with ANTLR, but I get a segfault always.
The source is pasted below, any suggestions?
The output is always:
--
cr at ....:~/dsl/output$ ./dsl ../install1.host_dsl
NetIP: 127.0.0.1
hlist size: 0
Segmentation fault
--
1. Snippet - class Host with Map:
---- 1. START
class Host {
private:
Network network;
Distribution distribution;
public:
Host();
Host(const Host& host);
~Host();
void setNetwork(Network network) { this->network = network; }
Network & getNetwork() { return this->network; }
void setDistribution(Distribution distri) { this->distribution = distri; }
Distribution & getDistribution() { return this->distribution; }
};
struct HostMapCompare {
bool operator()( const char* s1, const char* s2 ) const {
return strcmp( s1, s2 ) < 0;
}
};
typedef std::map<const char*, Host, HostMapCompare> HostList;
typedef std::map<const char*, Host, HostMapCompare>::iterator HostListIterator;
---- 1. END
---- 2. START
cluster :
host*
;
---- 2. END
---- 3. START
host
scope Symbols;
@init {
$Symbols::name->custom = new std::string();
$Symbols::name->freeCustom = freeName;
}
: 'Host' n=STRING {
$Symbols::name->custom = $n.text->chars;
}
OPEN_BRACE
host_values[$Symbols::name]
CLOSE_BRACE
;
host_values[pANTLR3_COMMON_TOKEN hostname]
@init {
std::string hostid;
Network network;
}
: {
hostid = (char*)hostname->custom;
hostid = hostid.substr(1,hostid.length()-2);
}
(
'distribution' ':' DISTRIBUTION END
| 'netip' ':' a=IP {network.setNetIp((char*)$a.text->chars);} END
| 'netgw' ':' b=IP {network.setNetGw((char*)$b.text->chars);} END
| 'netns' ':' c=IP {network.setNetNs((char*)$c.text->chars);} END
| 'netnm' ':' d=IP {network.setNetNm((char*)$d.text->chars);} END
| 'nethn' ':' STRING {network.setNetHn((char*)$STRING.text->chars);} END
)*
'services' ':' (ID|service) ((',' ID)|service)* END {
VisualGrid::Host h;
h.setNetwork(network);
std::cout << "NetIP: " << h.getNetwork().getNetIp() << std::endl;
std::cout << "hlist size: " << hlist.size() << std::endl;
hlist[hostid.c_str()] = h; // COULD NOT SET?!?!?!?!?
std::cout << "hlist size: " << hlist.size() << std::endl;
}
;
---- 3. END
--
============================================================================================
Dipl.-Ing. (FH) Christian Benjamin Ries
University of Applied Sciences Bielefeld
Department of Engineering Sciences and Mathematics
CMSE - Computational Materials Science& Engineering
Wilhelm-Bertelsmann-Str. 10
D-33602 Bielefeld
Office: 202 (WBS II)
Phone: +49 521 106-71222
Fax: +49 521 106-71241
http://www.christianbenjaminries.de
============================================================================================
More information about the antlr-interest
mailing list