1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// $Id: lisp.cpp 1024 2007-04-30 14:25:32Z hiker $
//
// TuxKart - a fun racing game with go-kart
// Copyright (C) 2004 Matthias Braun <matze@braunis.de>
// code in this file based on lispreader from Mark Probst
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "lisp.hpp"
#include <cstdio>
namespace lisp
{
Lisp::Lisp(LispType newtype)
: m_type(newtype)
{}
//-----------------------------------------------------------------------------
Lisp::~Lisp()
{
if(m_type == TYPE_SYMBOL || m_type == TYPE_STRING)
delete[] m_v.m_string;
if(m_type == TYPE_CONS)
{
delete m_v.m_cons.m_cdr;
delete m_v.m_cons.m_car;
}
}
//-----------------------------------------------------------------------------
const Lisp*
Lisp::getLisp(const char* name) const
{
const Lisp* P;
for(P = getCdr(); P != 0; P = P->getCdr())
{
const Lisp* CHILD = P->getCar();
// Also ignore if the child is not a CONS type, i.e.
// a TYPE_INTEGER is found, for which car is not defined!
if(!CHILD || CHILD->m_type!=TYPE_CONS)
continue;
if(!CHILD->getCar())
continue;
std::string CHILDName;
if(!CHILD->getCar()->get(CHILDName))
continue;
if(CHILDName == name)
return CHILD;
}
return 0;
}
//-----------------------------------------------------------------------------
//FIXME: is the boolean handled by this function? should the argument be
//removed?
void
Lisp::print(int ) const
{
if(m_type == TYPE_CONS)
{
printf("(");
if(m_v.m_cons.m_car)
m_v.m_cons.m_car->print();
if(m_v.m_cons.m_cdr)
{
printf(",");
if(m_v.m_cons.m_cdr)
m_v.m_cons.m_cdr->print();
}
printf(")");
}
if(m_type == TYPE_STRING)
{
printf("'%s' ", m_v.m_string);
}
if(m_type == TYPE_INTEGER)
{
printf("%d", m_v.m_integer);
}
if(m_type == TYPE_REAL)
{
printf("%f", m_v.m_real);
}
if(m_type == TYPE_SYMBOL)
{
printf("%s ", m_v.m_string);
}
}
} // end of namespace lisp
|