I have a txt file "blah.txt" which reads
word 3 + 6
Now consider the following code:
(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"))))
I'm not looking to output to a text file. I simply want to be able to move on to the next character. I've had unsuccessful attempts at solving it. Also for some reason I keep getting errors with char-numeric? and char-alphabetic? telling me that I have given it the eof instead of a what it expects when I save my file as 3 a + r (for example)
I know it involves changing it into a string but I keep getting a string of "word 3 + 6" for which I cannot do (car). let me explain that a little further I know you can do (define list file->list "blah.txt") which will contain '(word 3 + 4) but then doing (define str file->string "blah.txt") it will contain "word 3 + 4" and I cannot do (car str) to get "word" out because the whole (car) is "word 3 + 4" Please forgive me if I can't explain myself correctly as I am new to scheme