iris

small scheme interpreter
git clone git://git.2f30.org/iris
Log | Files | Refs | LICENSE

commit d8c92ecdb7344cd14ad018e66cbd9734c71e6f13
parent bebc3700274e39d89ee2eda2f01c6e20fa41bf07
Author: sin <sin@2f30.org>
Date:   Fri,  9 May 2014 16:58:55 +0100

Factor out lexer driver in a separate function

Diffstat:
Mrepl.c | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/repl.c b/repl.c @@ -6,26 +6,32 @@ #include "debug.h" #include "util.h" +static void +lexertest(char *buf) +{ + struct tok tok; + struct lexerctx ctx; + + resetlexer(&ctx); + do { + tok = gettok(&ctx, buf, strlen(buf)); + printtok(&tok); + putchar('\n'); + } while (tok.type != Eof && tok.type != Error); +} + int main(void) { char *buf = NULL; size_t sz = 0; - struct tok tok; - struct lexerctx ctx; puts("Welcome to iris, use ^C to quit"); do { printf("> "); fflush(stdout); - if (afgets(&buf, &sz, stdin)) { - resetlexer(&ctx); - do { - tok = gettok(&ctx, buf, strlen(buf)); - printtok(&tok); - putchar('\n'); - } while (tok.type != Eof && tok.type != Error); - } + if (afgets(&buf, &sz, stdin)) + lexertest(buf); if (ferror(stdin)) { fprintf(stderr, "input error\n"); return EXIT_FAILURE;