This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
10. Detection of Ptree position in the program text.
In some cases it is necessary to know in what places of the program text there is the code from which a particular Ptree object was built.
The function given below returns the address of the beginning and the end of memory space with the text of the program from which the mentioned Ptree object was created.
void GetPtreePos(const Ptree *p, const char *&begin,
const char *&end) {
if (p == NULL)
return;
if (p->IsLeaf()) {
const char *pos = p->GetLeafPosition();
if (begin == NULL) {
begin = pos;
} else {
begin = min(begin, pos);
}
end = max(end, pos);
}
else {
GetPtreePos(p->Car(), begin, end);
GetPtreePos(p->Cdr(), begin, end);
}
}
|