我有一个 txt 文件“blah.txt”,内容为
word 3 + 6
现在考虑以下代码:
(define c (read-char file))
(define (toke c)
(cond
((null? c)(write "empty"))
((equal? (read-char c) #\space)(write 'space)
; (toke (with the next character)
)
((equal? (read-char c) #\+) (write '+)
; (toke (with the next character)
)
((equal? (read-char c) #\-) (write '-)
; (toke (with the next character)
)
((equal? (read-char c) #\*) (write '*)
; (toke (with the next character)
)
((equal? (read-char c) #\/) (write '/)
; (toke (with the next character)
)
((equal? (read-char c) #\=) (write '=)
; (toke (with the next character)
)
((equal? (read-char c) #\() (write 'LPAREN)
; (toke (with the next character)
)
((equal? (read-char c) #\)) (write 'RPAREN)
; (toke (with the next character)
)
((char-numeric? (read-char c)) (write 'Num)
; (toke (with the next character)
)
((char-alphabetic? (read-char c))(write 'ID)
; (toke (with the next character)
)
(else
(write "error"))))
我不希望输出到文本文件。我只是希望能够继续下一个角色。我曾尝试解决它不成功。另外由于某种原因,我不断收到字符数字错误?和字符字母?告诉我,当我将文件另存为 3 a + r 时,我给了它 eof 而不是它所期望的(例如)
我知道这涉及将其更改为字符串,但我不断收到一串“单词 3 + 6”,但我无法做到(汽车)。让我再解释一下,我知道你可以做 (define list file->list "blah.txt") 将包含 '(word 3 + 4) 但然后做 (define str file->string "blah.txt" )它将包含“word 3 + 4”,我不能(car str)将“word”取出,因为整个(car)是“word 3 + 4”,如果我不能正确解释自己,请原谅我,因为我我是新来的计划