iris

small scheme interpreter
git clone git://git.2f30.org/iris
Log | Files | Refs | LICENSE

commit dcfba9294a0d4077eecf724686a858676711e642
parent 85261cadcde2f1b41211dd666c2caec6732a204a
Author: sin <sin@2f30.org>
Date:   Wed, 14 May 2014 14:14:19 +0100

Implementation quotation

Diffstat:
Mparser.c | 40++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/parser.c b/parser.c @@ -18,6 +18,7 @@ enum objtype { OString, OEmptylist, OPair, + OQuote, }; struct object { @@ -189,6 +190,16 @@ pair(FILE *in) } struct object * +quote(void) +{ + struct object *o; + + o = newobject(); + o->type = OQuote; + return o; +} + +struct object * sexpression(FILE *in) { struct tok t; @@ -216,6 +227,8 @@ sexpression(FILE *in) return string(l); case TLparen: return pair(in); + case TQuote: + return cons(quote(), cons(sexpression(in), emptylist())); default: return error("unhandled token"); } @@ -223,18 +236,41 @@ sexpression(FILE *in) return NULL; } +int +quoted(struct object *o) +{ + struct object *car; + + if (o->type == OPair) { + car = o->d.p.car; + return car->type == OQuote; + } + return 0; +} + struct object * eval(struct object *o) { struct object *otmp; + switch (o->type) { + /* self-evaluating objects */ + case OError: + case OEof: + case OBoolean: + case ONumber: + case OCharacter: + case OString: + return o; + } if (o->type == OIdentifier) { otmp = lookupsym(o->d.s.s); if (!otmp) return error("unbound identifier"); } - /* self-evaluating objects */ - return o; + if (quoted(o)) + return o->d.p.cdr->d.p.car; /* cadr */ + return error("cannot eval object"); } static void