Skip to content

Commit

Permalink
Completing noun parsing
Browse files Browse the repository at this point in the history
- Replaced strotd and strtol(eating exponential signs).
- Implemented exponent, complex and euler.

TODO
  + Pi times.
  + Base.
  + Complex angle or radians.
  + Exact Rationals.
  • Loading branch information
sazl committed Aug 19, 2010
1 parent 4ea811e commit 07f2f49
Show file tree
Hide file tree
Showing 26 changed files with 342 additions and 401 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

OBJS= memory.o util.o error.o convert.o atom.o noun.o function.o verb.o \
verb-scalar1.o verb-scalar2.o verb-atomic.o primitive.o adverb.o \
OBJS= memory.o util.o error.o convert.o noun.o function.o verb.o \
verb-scalar1.o verb-scalar2.o verb-atomic.o primitive.o adverb.o \
conjunction.o lexer.o parser.o test.o anicca.o

CFLAGS=-ansi -pedantic -g3
Expand All @@ -23,7 +23,6 @@ verb-atomic.o: verb-atomic.c verb-atomic.h
primitive.o: primitive.c primitive.h verb.h
function.o: function.c function.h
noun.o: noun.c noun.h util.h
atom.o: atom.c atom.h noun.h
convert.o: convert.c convert.h
error.o: error.c error.h
util.o: util.c util.h
Expand Down
26 changes: 6 additions & 20 deletions adverb.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,21 @@ MONAD(slash) {
ASSERT(AT(y)&VERB, ERDOM);
v = VAV(y);
z = ADERV(CFWSL, insert, table, y, VLR(v), VMR(v), VRR(v));
return z;
R z;
}

DMONAD(insert) {
A z = tail(y);
I r, n = AN(y), k = n-2;
if (n==1) { return z; }
return z;
}
DMONAD(insert) { A z; R z; }

DDYAD(table) {
A z;
return z;
}
DDYAD(table) { A z; R z; }

MONAD(tilde) {
V *v; A z;
ASSERT(AT(y)&VERB, ERDOM);
v = VAV(y);
z = ADERV(CTILDE, reflex, passive, y, VLR(v), VMR(v), VRR(v));
return z;
R z;
}

DMONAD(reflex) { DECL_F;
z = df2(y, y, f);
return z;
}
DMONAD(reflex) { DECL_F; z = df2(y, y, f); R z; }

DDYAD(passive) { DECL_F;
z = df2(y, x, f);
return z;
}
DDYAD(passive) { DECL_F; z = df2(y, x, f); R z; }
3 changes: 2 additions & 1 deletion anicca.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include "util.h"

I main(I argc, C *argv[]) {
A y, z;
a_init();
a_repl(" ");
return 0;
R 0;
}
10 changes: 5 additions & 5 deletions anicca.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ typedef double D;
typedef void VO;
typedef void* VP;

#define ZR(z) ((z).real)
#define ZI(z) ((z).imaginary)
#define ZR(z) ((z).re)
#define ZI(z) ((z).img)

typedef struct _complex {
D real;
D imaginary;
D re;
D img;
} Z;

#define AT(a) ((a)->type)
Expand Down Expand Up @@ -83,7 +83,7 @@ typedef A(*AF3)(A, A, A);
#define DMONAD(name) A name(A y, A self)
#define DDYAD(name) A name(A x, A y, A self)

A zero; A one;
A zero; A one; A zone;
A mark;
A lpar; A rpar;

Expand Down
38 changes: 0 additions & 38 deletions atom.c

This file was deleted.

23 changes: 0 additions & 23 deletions atom.h

This file was deleted.

60 changes: 18 additions & 42 deletions conjunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,90 +18,66 @@ DYAD(amper) {
v = VAV(y);
z = CDERV(CAMPR, compose, compose2, x, y, VLR(v), VMR(v), VRR(v));
}
return z;
R z;
}

DMONAD(bond) { DECL_FG;
z = AT(f)&NOUN ? df2(f, y, g) : df2(y, g, f);
return z;
}
DMONAD(bond) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(y,g,f); R z; }

DDYAD(bond2) { DECL_FG;
return z;
}
DDYAD(bond2) { DECL_FG; R z; }

DMONAD(compose) { DECL_FG;
z = df1(df1(y, g), f);
return z;
}
DMONAD(compose) { DECL_FG; z = df1(df1(y,g),f); R z; }

DDYAD(compose2) { DECL_FG;
z = df2(df1(x, g), df1(y, g), f);
return z;
}
DDYAD(compose2) { DECL_FG; z = df2(df1(x,g), df1(y,g),f); R z; }

DYAD(atsign) {
V *v; A z;
if (AT(x)&VERB && AT(y)&VERB) {
v = VAV(y);
z = CDERV(CAT, atop, atop2, x, y, VLR(v), VMR(v), VRR(v));
}
return z;
R z;
}

DMONAD(atop) {
A z;
z = compose(y, self);
return z;
}
DMONAD(atop) { A z; z = compose(y,self); R z; }

DDYAD(atop2) { DECL_FG;
z = df1(df2(x, y, g), f);
return z;
}
DDYAD(atop2) { DECL_FG; z = df1(df2(x,y,g),f); R z; }

DMONAD(hook) { DECL_FG;
z = df2(y, df1(y, g), f);
return z;
}
DMONAD(hook) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(y,df1(y,g),f); R z; }

DDYAD(hook2) { DECL_FG;
z = df2(x, df1(y, g), f);
return z;
}
DDYAD(hook2) { DECL_FG; z = AT(f)&NOUN ? df2(f,y,g) : df2(x,df1(y,g),f); R z; }

DMONAD(forrk) { DECL_FGH;
z = (AT(f)&VERB && VID(VAV(f))==CCAP) ? df1(df1(y, h), g) :
AT(f)&NOUN ? df2(f, df1(y, h), g) :
df2(df1(y, f), df1(y, h), g);
return z;
R z;
}

DDYAD(forrk2) { DECL_FGH;
z = (AT(f)&VERB && VID(VAV(f))==CCAP) ? df1(df2(x, y, h), g) :
AT(f)&NOUN ? df2(f, df2(x, y, h), g) :
df2(df2(x, y, f), df2(x, y, h), g);
return z;
R z;
}

DYAD(cartcol) {
V *v; A z; I xt = AT(x), yt = AT(y);
ASSERT(xt&VERB && yt&INT, ERDOM);
v = VAV(xt&VERB ? x : y);
z = CDERV(CPOWR, power, power2, x, y, VLR(v), VMR(v), VRR(v));
return z;
z = CDERV(CPOWR, cpower, cpower2, x, y, VLR(v), VMR(v), VRR(v));
R z;
}

DMONAD(power) { DECL_FG;
DMONAD(cpower) { DECL_FG;
I n = *IAV(g); A temp;
DO(n, temp = y; y = df1(temp, f); a_free(temp));
z = y;
return z;
R z;
}

DDYAD(power2) { DECL_FG;
DDYAD(cpower2) { DECL_FG;
I n = *IAV(g); A temp;
DO(n, temp = y; y = df2(x, temp, f); a_free(temp));
z = y;
return z;
R z;
}
4 changes: 2 additions & 2 deletions conjunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DDYAD(atop2);
DMONAD(hook);
DDYAD(hook2);
DYAD(cartcol);
DMONAD(power);
DDYAD(power2);
DMONAD(cpower);
DDYAD(cpower2);
DMONAD(forrk);
DDYAD(forrk2);

Expand Down
14 changes: 10 additions & 4 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
#include "memory.h"
#include "convert.h"

B cbTi(I n, I *iv, B *bv) { DO(n, iv[i] = (I)bv[i]); R 1; }
B cbTd(I n, D *dv, B *bv) { DO(n, dv[i] = (D)bv[i]); R 1; }
B ciTd(I n, D *dv, I *iv) { DO(n, dv[i] = (D)iv[i]); R 1; }
B cbTi(I n, I *iv, B *bv) { DO(n, iv[i]=(I)bv[i]); R 1; }
B cbTd(I n, D *dv, B *bv) { DO(n, dv[i]=(D)bv[i]); R 1; }
B cbTz(I n, Z *zv, B *bv) { DO(n, ZR(zv[i])=(D)bv[i]; ZI(zv[i])=0); R 1; }
B ciTd(I n, D *dv, I *iv) { DO(n, dv[i]=(D)iv[i]); R 1; }
B ciTz(I n, Z *zv, I *iv) { DO(n, ZR(zv[i])=(D)iv[i]; ZI(zv[i])=0); R 1; }
B cdTz(I n, Z *zv, D *dv) { DO(n, ZR(zv[i])=dv[i]; ZI(zv[i])=0); R 1; }

B aconv(I cv, I n, VP z, VP y) {
B *bv; I *iv; D *dv;
B *bv; I *iv; D *dv; Z *zv;
switch(cv) {
case BtI: bv=(B*)y; iv=(I*)z; cbTi(n,iv,bv); break;
case BtD: bv=(B*)y; dv=(D*)z; cbTd(n,dv,bv); break;
case BtZ: bv=(B*)y; zv=(Z*)z; cbTz(n,zv,bv); break;
case ItD: iv=(I*)y; dv=(D*)z; ciTd(n,dv,iv); break;
case ItZ: iv=(I*)y; zv=(Z*)z; ciTz(n,zv,iv); break;
case DtZ: dv=(D*)y; zv=(Z*)z; cdTz(n,zv,dv); break;
}
R 1;
}
Expand Down
3 changes: 3 additions & 0 deletions convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
*/
B cbTi(I n, I *iv, B *bv);
B cbTd(I n, D *dv, B *bv);
B cbTz(I n, Z *zv, B *bv);
B ciTd(I n, D *dv, I *iv);
B ciTz(I n, Z *zv, I *iv);
B cdTz(I n, Z *zv, D *dv);

B aconv(I cv, I n, VP z, VP y);
A conv(I t, A y);
Expand Down
16 changes: 8 additions & 8 deletions function.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
DMONAD(df1) {
V *v = VAV(self);
A z = VF(v)&&VDF1(v) ? v->df1(y, self) : v->f1(y);
return z;
R z;
}

DDYAD(df2) {
V *v = VAV(self);
A z = VF(v)&&VDF2(v) ? v->df2(x, y, self) : v->f2(x, y);
return z;
R z;
}

DMONAD(dhk) {
V *v = VAV(y);
return ddef(CHOOK,VERB,hook,hook2,y,self,NULL,VLR(v),VMR(v),VRR(v),0);
R ddef(CHOOK,VERB,hook,hook2,y,self,NULL,VLR(v),VMR(v),VRR(v),0);
}

DDYAD(dfrk) {
V *v = VAV(x);
return ddef(CFORK,VERB,forrk,forrk2,x,y,self,VLR(v),VMR(v),VRR(v),0);
R ddef(CFORK,VERB,forrk,forrk2,x,y,self,VLR(v),VMR(v),VRR(v),0);
}

/*
Expand Down Expand Up @@ -68,7 +68,7 @@ A sex1(A y, I zt, SF f1) {
C *yv = CAV(y), *zv = CAV(z);
zv -= zk; yv -= k;
DO(yn, f1(zv+=zk, yv+=k));
return z;
R z;
}

/*
Expand All @@ -89,7 +89,7 @@ A sex2(A x, A y, I zt, SF f2) {
A z = ga(zt, b ? yr : xr, m*n, b ? ys : xs);
C *xv = CAV(x), *yv = CAV(y), *zv = CAV(z);
ado(b, m, n, k, zk, zv, xv, yv, f2);
return z;
R z;
}

A fdef(UC id, I t, AF1 f1, AF2 f2, A f, A g, A h, I lr, I mr, I rr, I inv) {
Expand All @@ -101,12 +101,12 @@ A fdef(UC id, I t, AF1 f1, AF2 f2, A f, A g, A h, I lr, I mr, I rr, I inv) {
VLR(v) = lr; VMR(v) = mr; VRR(v) = rr;
VIR(v) = inv;
VID(v) = id;
return z;
R z;
}

A ddef(UC id, I t, AF2 df1, AF3 df2, A f, A g, A h, I lr, I mr, I rr, I inv) {
A z = fdef(id, t, NULL, NULL, f, g, h, lr, mr, rr, inv);
V *v = VAV(z);
VDF1(v) = df1; VDF2(v) = df2;
return z;
R z;
}
Loading

0 comments on commit 07f2f49

Please sign in to comment.