Mercurial > ~dholland > hg > ag > index.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * tree.cpp | |
7 */ | |
8 | |
9 #include "assert.h" | |
10 #include "csexp.h" | |
11 #include "tree.h" | |
12 | |
13 //#define INCLUDE_LOGGING | |
14 #include "log.h" | |
15 | |
16 | |
17 | |
18 int parse_tree_map::operator < (const parse_tree_map &t) const { | |
19 LOGSECTION_OFF("parse_tree_map::operator <"); | |
20 LOGV(expression != 0 ? expression->asString() : AgString()); | |
21 LOGV(t.expression != 0 ? t.expression->asString() : AgString()); | |
22 | |
23 if (expression && t.expression) { | |
24 return *expression < *t.expression; | |
25 } | |
26 if (expression == 0) { | |
27 return t.expression != 0; | |
28 } | |
29 return 0; | |
30 } | |
31 | |
32 ParseTree::ParseTree(unsigned x) | |
33 : KeyedObjectRegister<parse_tree_map>(x) | |
34 {} | |
35 | |
36 ParseTree::ParseTree(const ParseTree &t) | |
37 : KeyedObjectRegister<parse_tree_map>(t) | |
38 {} | |
39 | |
40 ParseTree::ParseTree(CharSetExpression *x) | |
41 : KeyedObjectRegister<parse_tree_map>(parse_tree_map(x)) | |
42 { | |
43 LOGSECTION("ParseTree::ParseTree"); | |
44 LOGV(index) LCV(x == 0 ? AgString() : x->asString()); | |
45 LOGV((int) x) LCV((int) descriptor->expression); | |
46 | |
47 if (descriptor->expression != x) { | |
48 delete x; | |
49 } | |
50 } | |
51 | |
52 parse_tree_map &ParseTree::Map::operator [] (unsigned x) { | |
53 assert(x < ParseTree::descriptorList.size()); | |
54 return ParseTree::descriptorList[x]; | |
55 } | |
56 | |
57 void ParseTree::reset() { | |
58 LOGSECTION("ParseTree::reset"); | |
59 int n = descriptorList.size(); | |
60 while (n-- > 0) { | |
61 delete descriptorList[n].expression; | |
62 } | |
63 KeyedObjectRegister<parse_tree_map>::reset(); | |
64 //descriptorList.push(parse_tree_map()); | |
65 ParseTree parseTree((CharSetExpression *) 0); | |
66 } | |
67 | |
68 parse_tree_map::parse_tree_map() | |
69 : expression(0), char_set(0) | |
70 { | |
71 // Nothing to do | |
72 } | |
73 | |
74 parse_tree_map::parse_tree_map(CharSetExpression *x) | |
75 : expression(x), char_set(0) | |
76 { | |
77 LOGSECTION("parse_tree_map::parse_tree_map"); | |
78 LOGV((int) this) LCV((int) x); | |
79 } | |
80 | |
81 ParseTree::Map map_parse_tree; | |
82 |