Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/agcore/tree.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children | 607e3be6bad8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/agcore/tree.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,82 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * tree.cpp + */ + +#include "assert.h" +#include "csexp.h" +#include "tree.h" + +//#define INCLUDE_LOGGING +#include "log.h" + + + +int parse_tree_map::operator < (const parse_tree_map &t) const { + LOGSECTION_OFF("parse_tree_map::operator <"); + LOGV(expression != 0 ? expression->asString() : AgString()); + LOGV(t.expression != 0 ? t.expression->asString() : AgString()); + + if (expression && t.expression) { + return *expression < *t.expression; + } + if (expression == 0) { + return t.expression != 0; + } + return 0; +} + +ParseTree::ParseTree(unsigned x) + : KeyedObjectRegister<parse_tree_map>(x) +{} + +ParseTree::ParseTree(const ParseTree &t) + : KeyedObjectRegister<parse_tree_map>(t) +{} + +ParseTree::ParseTree(CharSetExpression *x) + : KeyedObjectRegister<parse_tree_map>(parse_tree_map(x)) +{ + LOGSECTION("ParseTree::ParseTree"); + LOGV(index) LCV(x == 0 ? AgString() : x->asString()); + LOGV((int) x) LCV((int) descriptor->expression); + + if (descriptor->expression != x) { + delete x; + } +} + +parse_tree_map &ParseTree::Map::operator [] (unsigned x) { + assert(x < ParseTree::descriptorList.size()); + return ParseTree::descriptorList[x]; +} + +void ParseTree::reset() { + LOGSECTION("ParseTree::reset"); + int n = descriptorList.size(); + while (n-- > 0) { + delete descriptorList[n].expression; + } + KeyedObjectRegister<parse_tree_map>::reset(); + //descriptorList.push(parse_tree_map()); + ParseTree parseTree((CharSetExpression *) 0); +} + +parse_tree_map::parse_tree_map() + : expression(0), char_set(0) +{ + // Nothing to do +} + +parse_tree_map::parse_tree_map(CharSetExpression *x) + : expression(x), char_set(0) +{ + LOGSECTION("parse_tree_map::parse_tree_map"); + LOGV((int) this) LCV((int) x); +} + +ParseTree::Map map_parse_tree; +