On Monday, June 24, 2013 2:48:49 AM UTC-5, luser- -droog wrote:
> I hacked my string scanner into the eval-loop, and discovered a bug that xpost2 almost certainly has too.
Nope. xpost2 had already faced that one. forgot to check. :)
The current challenge is finishing-up a new translation of the scanner,
this time back to C.
The issue is building procedures. This is where the scanner calls
itself recursively, becoming a "parser" in so doing (where everywhere
else it may be treated as a deterministic automaton).
I've got two versions to draw from. The recent translation into
postscript
/* ({)0 get {
pop
mark exch % [ s'
{ % [ ... s'
toke % [ ... s' t b
not { syntaxerror } if % [ ... s' t
dup (}) cvn eq { % [ ... s' t
pop % [ ... s'
counttomark 1 add 1 roll % s' [ ...
] cvx exit
} if % [ ... s' t
exch % [ ... t s'
} loop % s' {}
%true % s' {} true
} */
And the earlier C version.
case '{': {
object *a;
size_t na = 100;
size_t i;
object proc;
object fin;
fin = consname(st,"}");
(a = malloc(na * sizeof(object))) || (fatal("failure to malloc"),0);
for (i=0 ; objcmp(st,a[i]=toke(st,src,next,back),fin) != 0; i++) {
if (i == na-1)
(a = realloc(a, (na+=100) * sizeof(object))) || (fatal("failure to malloc"),0);
}
proc = consarray(st,i);
{ size_t j;
for (j=0; j<i; j++) {
a_put(st, proc, j, a[j]);
}
}
free(a);
return proc;
}
Very different. I intend the result to be a hybrid of the two.
Using the stack to build the array, since it's already extensible
(and not 64k limited), but being in C, which the second ...
... uh ... is.
The second one doesn't have a lot going for it. It's a lot better
than the linked-list nonsense it evolved from. It's pretty short,
fairly easy to read (if you pardon the not-very-C-like
malloc||fatal idioms); but, uh. There's something not quite right.
Can't quite put a finger on it. It's not defining a crazy
local structure type like previous versions. But it's allocating
memory! And it's not using any of my painstakingly-designed
memory architecture! It just skips my whole garbage collector!
My beautiful tables. I like this code. I reared it like a child.
Now begone, wretched (w)realloc!
This is going nowhere.
My vacation ends today. :(