iris

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

commit 1545da6d1f889b904a1875afc0e5b391b4cbce51
parent b39794bf4533e83cc46678f1e1435185db02816d
Author: sin <sin@2f30.org>
Date:   Fri,  9 May 2014 15:52:54 +0100

Factor out printtok() to debug.c

Diffstat:
MMakefile | 2+-
Adebug.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adebug.h | 2++
Mlexer.c | 51---------------------------------------------------
Mlexer.h | 1-
Mrepl.c | 1+
6 files changed, 58 insertions(+), 53 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ BIN = iris VER = 0.0 -SRC = lexer.c parser.c repl.c +SRC = debug.c lexer.c parser.c repl.c OBJ = ${SRC:.c=.o} CC = gcc diff --git a/debug.c b/debug.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <stdlib.h> +#include "lexer.h" +#include "debug.h" + +void +printtok(struct tok *tok) +{ + char *s; + + s = extractstring(tok); + if (!s) + return; + switch (tok->type) { + case Error: + printf("Error: '%s'", s); + break; + case Eof: + printf("Eof"); + break; + case Identifier: + printf("Identifier: '%s'", s); + break; + case Boolean: + printf("Boolean: '%s'", s); + break; + case Number: + printf("Number: '%s'", s); + break; + case Character: + printf("Character: '%s'", s); + break; + case String: + printf("String: '%s'", s); + break; + case Lparen: + printf("Lparen: '%s'", s); + break; + case Rparen: + printf("Rparen: '%s'", s); + break; + case Quote: + printf("Quote: '%s'", s); + break; + case Dot: + printf("Dot: '%s'", s); + break; + default: + printf("Unknown token type: %d", tok->type); + break; + } + free(s); +} diff --git a/debug.h b/debug.h @@ -0,0 +1,2 @@ +/* See LICENSE file for copyright and license details. */ +void printtok(struct tok *); diff --git a/lexer.c b/lexer.c @@ -1,7 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> #include <string.h> #include "lexer.h" @@ -225,55 +223,6 @@ gettok(struct lexerctx *ctx, const char *buf, size_t len) } void -printtok(struct tok *tok) -{ - char *s; - - s = extractstring(tok); - if (!s) - return; - switch (tok->type) { - case Error: - printf("Error: '%s'", s); - break; - case Eof: - printf("Eof"); - break; - case Identifier: - printf("Identifier: '%s'", s); - break; - case Boolean: - printf("Boolean: '%s'", s); - break; - case Number: - printf("Number: '%s'", s); - break; - case Character: - printf("Character: '%s'", s); - break; - case String: - printf("String: '%s'", s); - break; - case Lparen: - printf("Lparen: '%s'", s); - break; - case Rparen: - printf("Rparen: '%s'", s); - break; - case Quote: - printf("Quote: '%s'", s); - break; - case Dot: - printf("Dot: '%s'", s); - break; - default: - printf("Unknown token type: %d", tok->type); - break; - } - free(s); -} - -void resetlexer(struct lexerctx *ctx) { ctx->ready = 0; diff --git a/lexer.h b/lexer.h @@ -28,5 +28,4 @@ struct lexerctx { int delim(int); char *extractstring(struct tok *); struct tok gettok(struct lexerctx *, const char *, size_t); -void printtok(struct tok *); void resetlexer(struct lexerctx *); diff --git a/repl.c b/repl.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <string.h> #include "lexer.h" +#include "debug.h" int main(void)