mes.c: when reading `EOF', defer read control to program.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-24 18:28:45 +02:00
parent 8dacd68fe8
commit 46387d411b
3 changed files with 14 additions and 10 deletions

View file

@ -84,8 +84,7 @@ record: all
paren: all
cat scm.mes syntax.mes lib/srfi/srfi-0.scm lib/record.mes lib/record.scm lib/srfi/srfi-9.scm lib/lalr.mes lib/lalr.scm paren.scm | ./mes
# #echo '___P((()))'
echo -e 'EOF\n___P((()))' | cat scm.mes syntax.mes lib/srfi/srfi-0.scm lib/record.mes lib/record.scm lib/srfi/srfi-9.scm lib/lalr.mes lib/lalr.scm paren.scm - | ./mes
paren.test: lib/lalr.scm paren.scm
cat $^ > $@

18
mes.c
View file

@ -738,6 +738,10 @@ lookup (char *x, scm *a)
if (*x == '#' && *(x+1) == ',' && *(x+2) == '@') return &symbol_unsyntax_splicing;
if (*x == '#' && *(x+1) == ',') return &symbol_unsyntax;
if (!strcmp (x, "EOF")) {
fprintf (stderr, "mes: got EOF\n");
return &scm_nil; // `EOF': eval program, which may read stdin
}
return make_symbol (x);
}
@ -921,13 +925,13 @@ peek_char () //int
}
scm*
builtin_getchar ()
builtin_peek_char ()
{
return make_number (getchar ());
return make_char (peek_char ());
}
scm*
builtin_peek_char ()
scm *
read_char ()
{
return make_char (getchar ());
}
@ -990,8 +994,8 @@ readword (int c, char* w, scm *a)
&& !w) {char buf[3] = "#"; buf[1] = getchar (); return cons (lookup (buf, a),
cons (readword (getchar (), w, a),
&scm_nil));}
if (c == ';') {readcomment (c); return readword ('\n', w, a);}
if (c == '#' && peek_char () == '\\') {getchar (); return read_char ();}
if (c == ';') {readcomment (c); return readword ('\n', w, a);}
if (c == '#' && peek_char () == '\\') {getchar (); return read_character ();}
if (c == '#' && !w && peek_char () == '(') {getchar (); return list_to_vector (readlist (a));}
if (c == '#' && peek_char () == '(') {ungetchar (c); return lookup (w, a);}
if (c == '#' && peek_char () == '!') {getchar (); readblock (getchar ()); return readword (getchar (), w, a);}
@ -1001,7 +1005,7 @@ readword (int c, char* w, scm *a)
}
scm *
read_char ()
read_character ()
{
int c = getchar ();
if (c >= '0' && c <= '7'

View file

@ -262,7 +262,8 @@
(append (reverse (cdr lst)) (cons (car lst) '()))))
(define (eof-object? x)
(and (number? x) (= x -1)))
(or (and (number? x) (= x -1))
(and (char? x) (eof-object? (char->integer x)))))
(define (char=? x y)
(and (char? x) (char? y)