iris

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

commit 0c6362ecb363c22fe03ec2736e06928660ddc1b9
parent 5e7446c16a6a4e0cf40fdc4b6600c66f209347e4
Author: sin <sin@2f30.org>
Date:   Wed May 14 11:43:54 +0100

Parse identifiers too

Diffstat:
parser.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/parser.c b/parser.c @@ -81,6 +81,17 @@ eof(void) } static struct object * +identifier(char *s) +{ + struct object *o; + + o = newobject(); + o->type = OIdentifier; + o->d.b.v = estrdup(s); + return o; +} + +static struct object * boolean(bool v) { struct object *o; @@ -138,6 +149,8 @@ sexpression(FILE *in) return eof(); case TError: return error(l); + case TIdentifier: + return identifier(l); case TBoolean: return boolean(l[1] == 't' ? true : false); case TNumber: @@ -155,8 +168,15 @@ sexpression(FILE *in) struct object * eval(struct object *o) { + struct object *otmp; if (!o) return error("asked to eval nil-object"); + if (o->type == OIdentifier) { + otmp = lookupsym(o->d.s.s); + if (!otmp) + return error("unbound identifier"); + } + /* self-evaluating objects */ return o; }