From bad998157c95851eb29d3e4f6824a276d7032b12 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 4 Nov 2024 20:13:50 -0500 Subject: Add modules, open port for reading --- src/modules/lexer/lexer.scm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/modules/lexer/lexer.scm (limited to 'src/modules/lexer') diff --git a/src/modules/lexer/lexer.scm b/src/modules/lexer/lexer.scm new file mode 100644 index 0000000..0661fa6 --- /dev/null +++ b/src/modules/lexer/lexer.scm @@ -0,0 +1,31 @@ +(define-module (modules lexer lexer) + #:export (read-tokens-from-port)) + +(define (read-tokens-from-port port) + "" + (display (read-char port))) + +(define (read-token) + + (define (read-token-loop first-char) + (cond + + ((or (char-whitespace? first-char)) + (read-token) + + ((eq? first-char #\() + (cons 'left-paren #\()) + ((eq? first-char #\)) + (cons 'right-paren #\))) + ((eq? first-char #\{) + (cons 'right-bracket #\{)) + ((eq? first-char #\}) + (cons 'right-bracket #\})) + + (#t + (error "illegal lexical syntax"))))) + + (let ((first-char (read-char))) + (if (eof-object? first-char) + '() + (cons (read-token-loop first-char) '())))) -- cgit v1.2.3