diff options
author | FWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544> | 2011-12-08 14:53:40 +0000 |
---|---|---|
committer | FWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544> | 2011-12-08 14:53:40 +0000 |
commit | e33e19d0587146859d48a134ec9fd94e7b7ba5cd (patch) | |
tree | 69d048c8801858d2756ab3a487090a7a1b74bf14 /Parser/Term.cpp | |
download | starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.zip starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.tar.gz starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.tar.bz2 |
Initial upload
Diffstat (limited to 'Parser/Term.cpp')
-rw-r--r-- | Parser/Term.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/Parser/Term.cpp b/Parser/Term.cpp new file mode 100644 index 0000000..5c5f9d4 --- /dev/null +++ b/Parser/Term.cpp @@ -0,0 +1,122 @@ +/* Project STARS
+ John DiCamillo Software Consulting
+ Copyright © 1997-2000. All Rights Reserved.
+
+ SUBSYSTEM: Stars
+ FILE: Term.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Implementation of the Term class
+*/
+
+
+#include "MemDebug.h"
+#include "Term.h"
+
+void Print(const char* fmt, ...);
+
+// +-------------------------------------------------------------------+
+
+Term*
+error(char* s1, char* s2)
+{
+ Print("ERROR: ");
+ if (s1) Print(s1);
+ if (s2) Print(s2);
+ Print("\n\n");
+ return 0;
+}
+
+// +-------------------------------------------------------------------+
+
+void TermBool::print(int level) { if (level > 0) Print(val? "true" : "false"); else Print("..."); }
+void TermNumber::print(int level){ if (level > 0) Print("%g", val); else Print("..."); }
+void TermText::print(int level) { if (level > 0) Print("\"%s\"", val); else Print("..."); }
+
+// +-------------------------------------------------------------------+
+
+TermArray::TermArray(TermList* elist)
+{
+ elems = elist;
+}
+
+TermArray::~TermArray()
+{
+ if (elems) elems->destroy();
+ delete elems;
+}
+
+void
+TermArray::print(int level)
+{
+ if (level > 1) {
+ Print("(");
+
+ if (elems) {
+ for (int i = 0; i < elems->size(); i++) {
+ elems->at(i)->print(level-1);
+ if (i < elems->size() -1)
+ Print(", ");
+ }
+ }
+
+ Print(") ");
+ }
+ else Print("(...) ");
+}
+
+// +-------------------------------------------------------------------+
+
+TermStruct::TermStruct(TermList* elist)
+{
+ elems = elist;
+}
+
+TermStruct::~TermStruct()
+{
+ if (elems) elems->destroy();
+ delete elems;
+}
+
+void
+TermStruct::print(int level)
+{
+ if (level > 1) {
+ Print("{");
+
+ if (elems) {
+ for (int i = 0; i < elems->size(); i++) {
+ elems->at(i)->print(level-1);
+ if (i < elems->size() -1)
+ Print(", ");
+ }
+ }
+
+ Print("} ");
+ }
+ else Print("{...} ");
+}
+
+// +-------------------------------------------------------------------+
+
+TermDef::~TermDef()
+{
+ delete mname;
+ delete mval;
+}
+
+void
+TermDef::print(int level)
+{
+ if (level >= 0) {
+ mname->print(level);
+ Print(": ");
+ mval->print(level-1);
+ }
+ else Print("...");
+}
+
+// +-------------------------------------------------------------------+
|