Added I/O
This commit is contained in:
parent
afe94cf84b
commit
44d5893139
|
@ -0,0 +1,3 @@
|
|||
<> ((send ?:)) ()
|
||||
|
||||
(send (hello world))
|
|
@ -1,3 +1,5 @@
|
|||
<> ((read)) (?:)
|
||||
<> ((send ?:)) ()
|
||||
<> (?x ?y catswap) ((?y ?x))
|
||||
|
||||
(send (hello world))
|
||||
(send (You said: )) (read) send catswap
|
4
makefile
4
makefile
|
@ -8,10 +8,10 @@ all: dest bin/modal
|
|||
dest:
|
||||
@ mkdir -p bin
|
||||
run: all
|
||||
@ bin/modal examples/test.modal 2> /dev/null
|
||||
@ bin/modal examples/test.modal "(arg1)" "(arg2)" "(arg3)"
|
||||
test: all
|
||||
@ bin/modal -v
|
||||
@ bin/modal examples/test.modal
|
||||
@ bin/modal examples/test.modal 2> /dev/null
|
||||
install: all
|
||||
cp bin/modal ~/bin/
|
||||
uninstall:
|
||||
|
|
12
src/modal.c
12
src/modal.c
|
@ -4,7 +4,7 @@ typedef struct {
|
|||
char *a, *b;
|
||||
} Rule;
|
||||
|
||||
static int rules_len, direction = 0;
|
||||
static int rules_len, direction, queue;
|
||||
static Rule rules[0x100];
|
||||
static char dict[0x8000], *dict_ = dict;
|
||||
static char bank_a[0x4000], *prog_ = bank_a;
|
||||
|
@ -77,10 +77,11 @@ match(char *p, Rule *r)
|
|||
}
|
||||
|
||||
static int
|
||||
bind(char r)
|
||||
bind(char r, char *incoming)
|
||||
{
|
||||
int depth = 0;
|
||||
char c, *s = regs[(int)r];
|
||||
if(r == ':' && incoming != NULL) s = incoming, queue++;
|
||||
if(!s) return !fprintf(stderr, "?%c Empty\n", r);
|
||||
if(s[0] == '(') {
|
||||
while((c = *s++)) {
|
||||
|
@ -147,7 +148,7 @@ addrule(char *s)
|
|||
}
|
||||
|
||||
static int
|
||||
rewrite(void)
|
||||
rewrite(char *incoming)
|
||||
{
|
||||
char c, *p = direction ? bank_b : bank_a;
|
||||
while((c = *p)) {
|
||||
|
@ -167,7 +168,7 @@ rewrite(void)
|
|||
char cc, *b = r->b;
|
||||
while((cc = *b++)) {
|
||||
if(cc == '?')
|
||||
bind(*b++);
|
||||
bind(*b++, incoming);
|
||||
else
|
||||
*outp_++ = cc;
|
||||
}
|
||||
|
@ -206,8 +207,9 @@ main(int argc, char **argv)
|
|||
return !printf("Modal - Modal Interpreter, 4 Apr 2024.\n");
|
||||
if(!(f = fopen(argv[1], "r")))
|
||||
return !printf("Invalid Modal file: %s.\n", argv[1]);
|
||||
queue = 2;
|
||||
fread(bank_a, 1, 0x1000, f), fclose(f);
|
||||
while(rewrite())
|
||||
while(rewrite(argv[queue]))
|
||||
;
|
||||
print_rules();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue