This commit is contained in:
parent
91b68104d0
commit
557dfcbecf
16
src/modal.c
16
src/modal.c
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
char *a, *b;
|
||||
|
@ -56,6 +57,7 @@ static int
|
|||
rewrite(void)
|
||||
{
|
||||
char c, *p = prog;
|
||||
printf("STEP ---------\n");
|
||||
while((c = *p)) {
|
||||
int i, found = 0;
|
||||
for(i = 0; i < rules_len; i++) {
|
||||
|
@ -63,6 +65,7 @@ rewrite(void)
|
|||
char *res = match(p, r);
|
||||
if(res != NULL) {
|
||||
char cc, *b = r->b;
|
||||
printf("MATCH: %s -> %s\n", r->a, r->b);
|
||||
while((cc = *b++)) {
|
||||
if(cc == '?')
|
||||
writereg(*b++);
|
||||
|
@ -78,6 +81,7 @@ rewrite(void)
|
|||
p++;
|
||||
}
|
||||
}
|
||||
*outp_++ = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -143,6 +147,15 @@ parse(char *path)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
save(void)
|
||||
{
|
||||
int i, end = outp_ - outp;
|
||||
for(i = 0; i < end; i++)
|
||||
prog[i] = outp[i];
|
||||
prog[i] = 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
@ -153,5 +166,8 @@ main(int argc, char **argv)
|
|||
parse(argv[1]);
|
||||
rewrite();
|
||||
display();
|
||||
save();
|
||||
rewrite();
|
||||
display();
|
||||
return 0;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
<> (?x ?y swap) (?y ?x)
|
||||
<> (?x dup) (?x ?x)
|
||||
|
||||
foo (hey dup)
|
||||
foo ((A B swap) dup)
|
Loading…
Reference in New Issue