2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "lisp/lisp.hpp"
23 Lisp::Lisp(LispType newtype) :
31 // resources should be on parser obstack, so no need to delete anything
35 Lisp::get_lisp(const char* name) const
37 for(const Lisp* p = this; p != 0; p = p->get_cdr()) {
38 const Lisp* child = p->get_car();
39 if(!child || child->get_type() != TYPE_CONS)
41 const Lisp* childname = child->get_car();
44 std::string childName;
45 if(!childname->get(childName))
47 if(childName == name) {
48 return child->get_cdr();
56 Lisp::print(int indent) const
58 for(int i = 0; i < indent; ++i)
61 if(type == TYPE_CONS) {
63 const Lisp* lisp = this;
66 lisp->v.cons.car->print(indent + 1);
67 lisp = lisp->v.cons.cdr;
69 for(int i = 0; i < indent; ++i)
73 if(type == TYPE_STRING) {
74 printf("'%s' ", v.string);
76 if(type == TYPE_INTEGER) {
77 printf("%d", v.integer);
79 if(type == TYPE_REAL) {
82 if(type == TYPE_SYMBOL) {
83 printf("%s ", v.string);
85 if(type == TYPE_BOOLEAN) {
86 printf("%s ", v.boolean ? "true" : "false");
91 } // end of namespace lisp