Tokenizer beginnings

This commit is contained in:
2025-10-23 16:12:29 +02:00
parent a2313aa916
commit a1c91a623b
2 changed files with 33 additions and 1 deletions

View File

@@ -1 +1,32 @@
(print "Hello, world!")
(import (rnrs))
(define get-word
(lambda (file word)
(let ([c (lookahead-char file)])
(if (char-alphabetic? c)
(begin
(get-char file)
(get-word file (string-append word (string c))))
word))))
(define get-words
(lambda (file)
(letrec ([loop
(lambda (file words)
(let ([c (lookahead-char file)])
(cond
[(eof-object? c) words]
[(char-whitespace? c)
(get-char file)
(loop file words)]
[(char-alphabetic? c)
(loop file (cons (get-word file "") words))]
[else (error 'get-words "wtf" c)])))])
(reverse (loop file '())))))
(define tokenize
(lambda (filename)
(let ([file (open-input-file filename)])
(get-words file))))
(display (tokenize "tokens.txt"))

1
sigma Normal file
View File

@@ -0,0 +1 @@
Hello, world!