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)
30 // resources should be on parser obstack, so no need to delete anything
34 Lisp::get_lisp(const char* name) const
36 for(const Lisp* p = this; p != 0; p = p->get_cdr()) {
37 const Lisp* child = p->get_car();
38 if(!child || child->get_type() != TYPE_CONS)
40 const Lisp* childname = child->get_car();
43 std::string childName;
44 if(!childname->get(childName))
46 if(childName == name) {
47 return child->get_cdr();
55 Lisp::print(int indent) const
57 for(int i = 0; i < indent; ++i)
60 if(type == TYPE_CONS) {
62 const Lisp* lisp = this;
65 lisp->v.cons.car->print(indent + 1);
66 lisp = lisp->v.cons.cdr;
68 for(int i = 0; i < indent; ++i)
72 if(type == TYPE_STRING) {
73 printf("'%s' ", v.string);
75 if(type == TYPE_INTEGER) {
76 printf("%d", v.integer);
78 if(type == TYPE_REAL) {
81 if(type == TYPE_SYMBOL) {
82 printf("%s ", v.string);
84 if(type == TYPE_BOOLEAN) {
85 printf("%s ", v.boolean ? "true" : "false");
90 } // end of namespace lisp