3 // TuxKart - a fun racing game with go-kart
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de>
5 // code in this file based on lispreader from Mark Probst
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 Lisp::Lisp(LispType newtype)
34 if(type == TYPE_SYMBOL || type == TYPE_STRING)
36 if(type == TYPE_CONS) {
43 Lisp::get_lisp(const char* name) const
45 for(const Lisp* p = this; p != 0; p = p->get_cdr()) {
46 Lisp* child = p->get_car();
47 if(!child || child->get_type() != TYPE_CONS)
49 Lisp* childname = child->get_car();
52 std::string childName;
53 if(!childname->get(childName))
55 if(childName == name) {
56 return child->get_cdr();
64 Lisp::print(int indent) const
66 for(int i = 0; i < indent; ++i)
69 if(type == TYPE_CONS) {
71 const Lisp* lisp = this;
74 lisp->v.cons.car->print(indent + 1);
75 lisp = lisp->v.cons.cdr;
77 for(int i = 0; i < indent; ++i)
81 if(type == TYPE_STRING) {
82 printf("'%s' ", v.string);
84 if(type == TYPE_INTEGER) {
85 printf("%d", v.integer);
87 if(type == TYPE_REAL) {
90 if(type == TYPE_SYMBOL) {
91 printf("%s ", v.string);
93 if(type == TYPE_BOOLEAN) {
94 printf("%s ", v.boolean ? "true" : "false");
99 } // end of namespace lisp