Initial lambda support
This commit is contained in:
parent
d255500447
commit
3c5e3de38f
6
makefile
6
makefile
|
@ -10,9 +10,9 @@ dest:
|
||||||
run: all bin/modal
|
run: all bin/modal
|
||||||
@ bin/modal examples/hello.modal 2> /dev/null
|
@ bin/modal examples/hello.modal 2> /dev/null
|
||||||
test: bin/modal-debug bin/modal
|
test: bin/modal-debug bin/modal
|
||||||
@ bin/modal -v
|
# @ bin/modal -v
|
||||||
@ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
|
# @ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
|
||||||
@ time bin/modal examples/test.modal "(arg1) (arg2 (arg3))"
|
@ bin/modal examples/test.modal
|
||||||
install: bin/modal
|
install: bin/modal
|
||||||
cp bin/modal ~/bin/
|
cp bin/modal ~/bin/
|
||||||
uninstall:
|
uninstall:
|
||||||
|
|
31
src/modal.c
31
src/modal.c
|
@ -149,15 +149,38 @@ rewrite(void)
|
||||||
char c, last = 0, *p = direction ? bank_b : bank_a;
|
char c, last = 0, *p = direction ? bank_b : bank_a;
|
||||||
while((c = *p) && c <= ' ') p++;
|
while((c = *p) && c <= ' ') p++;
|
||||||
while((c = *p)) {
|
while((c = *p)) {
|
||||||
|
if(spacer(last)) {
|
||||||
|
Rule *r = NULL, lambda;
|
||||||
if(p[0] == '<' && p[1] == '>') {
|
if(p[0] == '<' && p[1] == '>') {
|
||||||
Rule *r = rules_++;
|
r = rules_++;
|
||||||
r->id = rules_ - rules - 1, p += 2;
|
r->id = rules_ - rules - 1;
|
||||||
|
p += 2;
|
||||||
r->a = dict_, p = parse_frag(p);
|
r->a = dict_, p = parse_frag(p);
|
||||||
r->b = dict_, p = parse_frag(p);
|
r->b = dict_, p = parse_frag(p);
|
||||||
return commit_rule(r, p, 1);
|
return commit_rule(r, p, 1);
|
||||||
}
|
}
|
||||||
if(spacer(last)) {
|
if(p[0] == '?' && p[1] == '(') {
|
||||||
Rule *r;
|
char *res;
|
||||||
|
p += 2;
|
||||||
|
lambda.a = dict_, p = parse_frag(p);
|
||||||
|
lambda.b = dict_, p = parse_frag(p);
|
||||||
|
p++;
|
||||||
|
while((c = *p) && c <= ' ') p++;
|
||||||
|
r = λ
|
||||||
|
res = match_rule(p, r);
|
||||||
|
if(res != NULL) {
|
||||||
|
char cc, *b = r->b;
|
||||||
|
printf("LAMBDA [%s][%s] > %s\n", r->a, r->b, p);
|
||||||
|
if(!*b && last == ' ') outp_--;
|
||||||
|
while((cc = *b++)) {
|
||||||
|
if(cc == '?')
|
||||||
|
put_reg(*b++);
|
||||||
|
else
|
||||||
|
*outp_++ = cc;
|
||||||
|
}
|
||||||
|
return commit_rule(r, res, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
for(r = rules; r < rules_; r++) {
|
for(r = rules; r < rules_; r++) {
|
||||||
char *res = match_rule(p, r);
|
char *res = match_rule(p, r);
|
||||||
if(res != NULL) {
|
if(res != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue