iris

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

commit 975ef834508906247bda5ad2d1492213eff4c0bf
parent 07c4f4c7c10d9fab9f86a93096ebea0ab29b8ec8
Author: sin <sin@2f30.org>
Date:   Thu, 15 May 2014 12:41:00 +0100

Fix indentation

Diffstat:
Mparser.c | 92+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 45 insertions(+), 47 deletions(-)

diff --git a/parser.c b/parser.c @@ -203,15 +203,15 @@ pair(FILE *in) puttok(t); car = sexpression(in); t = gettok(in); - if (t.type == TDot) { - cdr = sexpression(in); - t = gettok(in); - if (t.type != TRparen) - return error("missing right parenthesis"); + if (t.type != TDot) { + puttok(t); + cdr = pair(in); return cons(car, cdr); } - puttok(t); - cdr = pair(in); + cdr = sexpression(in); + t = gettok(in); + if (t.type != TRparen) + return error("missing right parenthesis"); return cons(car, cdr); } @@ -299,25 +299,24 @@ evaldefine(struct object *o) struct object *ocar; struct object *var, *val; - if (o->type == OPair) { - ocar = car(o); - if (ocar->type == OIdentifier && - strcmp(ocar->d.i.s, "define") == 0) { - var = cadr(o); - if (var->type != OIdentifier) - return error("expected identifier"); - if (!caddr(o)) - return error("expected sexpression"); - if (cadddr(o)) - return error("multiple arguments to define"); - val = eval(caddr(o)); - if (val->type == OError) - return val; - addsym(var->d.i.s, val); - return lookupsym("ok"); - } - } - return NULL; + if (o->type != OPair) + return NULL; + ocar = car(o); + if (ocar->type != OIdentifier || + strcmp(ocar->d.i.s, "define") != 0) + return NULL; + var = cadr(o); + if (var->type != OIdentifier) + return error("expected identifier"); + if (!caddr(o)) + return error("expected sexpression"); + if (cadddr(o)) + return error("multiple arguments to define"); + val = eval(caddr(o)); + if (val->type == OError) + return val; + addsym(var->d.i.s, val); + return lookupsym("ok"); } static struct object * @@ -349,27 +348,26 @@ evalset(struct object *o) struct object *ocar; struct object *var, *val; - if (o->type == OPair) { - ocar = car(o); - if (ocar->type == OIdentifier && - strcmp(ocar->d.i.s, "set") == 0) { - var = cadr(o); - if (var->type != OIdentifier) - return error("expected identifier"); - if (!lookupsym(var->d.i.s)) - return error("unbound identifier"); - if (!caddr(o)) - return error("expected sexpression"); - if (cadddr(o)) - return error("multiple arguments to set"); - val = eval(caddr(o)); - if (val->type == OError) - return val; - addsym(var->d.i.s, val); - return lookupsym("ok"); - } - } - return NULL; + if (o->type != OPair) + return NULL; + ocar = car(o); + if (ocar->type != OIdentifier || + strcmp(ocar->d.i.s, "set") != 0) + return NULL; + var = cadr(o); + if (var->type != OIdentifier) + return error("expected identifier"); + if (!lookupsym(var->d.i.s)) + return error("unbound identifier"); + if (!caddr(o)) + return error("expected sexpression"); + if (cadddr(o)) + return error("multiple arguments to set"); + val = eval(caddr(o)); + if (val->type == OError) + return val; + addsym(var->d.i.s, val); + return lookupsym("ok"); } struct object *