Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Term.cpp
Go to the documentation of this file.
1
/* Project STARS
2
John DiCamillo Software Consulting
3
Copyright (C) 1997-2000. All Rights Reserved.
4
5
SUBSYSTEM: Stars
6
FILE: Term.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Implementation of the Term class
13
*/
14
15
16
#include "
MemDebug.h
"
17
#include "
Term.h
"
18
19
void
Print
(
const
char
* fmt, ...);
20
21
// +-------------------------------------------------------------------+
22
23
Term
*
24
error
(
char
* s1,
char
* s2)
25
{
26
Print
(
"ERROR: "
);
27
if
(s1)
Print
(s1);
28
if
(s2)
Print
(s2);
29
Print
(
"\n\n"
);
30
return
0;
31
}
32
33
// +-------------------------------------------------------------------+
34
35
void
TermBool::print
(
int
level) {
if
(level > 0)
Print
(val?
"true"
:
"false"
);
else
Print
(
"..."
); }
36
void
TermNumber::print
(
int
level){
if
(level > 0)
Print
(
"%g"
, val);
else
Print
(
"..."
); }
37
void
TermText::print
(
int
level) {
if
(level > 0)
Print
(
"\"%s\""
, val.
data
());
else
Print
(
"..."
); }
38
39
// +-------------------------------------------------------------------+
40
41
TermArray::TermArray
(
TermList
* elist)
42
{
43
elems = elist;
44
}
45
46
TermArray::~TermArray
()
47
{
48
if
(elems) elems->
destroy
();
49
delete
elems;
50
}
51
52
void
53
TermArray::print
(
int
level)
54
{
55
if
(level > 1) {
56
Print
(
"("
);
57
58
if
(elems) {
59
for
(
int
i = 0; i < elems->
size
(); i++) {
60
elems->
at
(i)->print(level-1);
61
if
(i < elems->size() -1)
62
Print
(
", "
);
63
}
64
}
65
66
Print
(
") "
);
67
}
68
else
Print
(
"(...) "
);
69
}
70
71
// +-------------------------------------------------------------------+
72
73
TermStruct::TermStruct
(
TermList
* elist)
74
{
75
elems = elist;
76
}
77
78
TermStruct::~TermStruct
()
79
{
80
if
(elems) elems->
destroy
();
81
delete
elems;
82
}
83
84
void
85
TermStruct::print
(
int
level)
86
{
87
if
(level > 1) {
88
Print
(
"{"
);
89
90
if
(elems) {
91
for
(
int
i = 0; i < elems->
size
(); i++) {
92
elems->
at
(i)->print(level-1);
93
if
(i < elems->size() -1)
94
Print
(
", "
);
95
}
96
}
97
98
Print
(
"} "
);
99
}
100
else
Print
(
"{...} "
);
101
}
102
103
// +-------------------------------------------------------------------+
104
105
TermDef::~TermDef
()
106
{
107
delete
mname;
108
delete
mval;
109
}
110
111
void
112
TermDef::print
(
int
level)
113
{
114
if
(level >= 0) {
115
mname->
print
(level);
116
Print
(
": "
);
117
mval->
print
(level-1);
118
}
119
else
Print
(
"..."
);
120
}
121
122
// +-------------------------------------------------------------------+
Parser
Term.cpp
Generated on Thu May 31 2012 16:31:00 for Starshatter_Open by
1.8.1