[racket] Simple Scheme Interpreter written in Drracket

From: Peter Breitsprecher (pkbreits at lakeheadu.ca)
Date: Tue Nov 9 15:32:57 EST 2010

Ok, here is the code I have written so far for the function I am having
trouble with...

(define (rep-loop)
  (newline)
  (display "repl>")
  (read-token))

(define (read-token)
  (let ((expr (read-char)))
    ((cond [(char-whitespace? expr) (read-token1)]
           [(eq? expr #\() (read-token2)]
           [(eq? expr #\)) (read-token3)]
           [(char-alphabetic? expr) (read-token4)]
           [(char-numeric? expr) (read-token5)]
           [else (display "Exiting Loop")]))))

The cond calls other functions I have written just so I could see it if was
reading the output letter by letter...  Now I need to make read-token read
the whole word if it sees a character and the entire number if it sees a
number.

Is that getting closer?

On 9 November 2010 15:28, John Clements <clements at brinckerhoff.org> wrote:

>
> On Nov 9, 2010, at 12:27 PM, Peter Breitsprecher wrote:
>
> > I'd lie but no.. I was just trying to clarify what I was looking for.  I
> gave a the code for one of the functions I had written, and then an example
> of the input the user is giving below, and then tried to describe in more
> detail what I needed help with...
>
> Well, I'm glad you're not lying :).
>
> Can you start by picking a name for the function that you're trying to
> write?
>
> John Clements
>
>
> > On 9 November 2010 15:23, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:
> > Hi,
> >
> > That would not be considered an "example" for at least two reasons. Do
> you see why?
> >
> >
> >> On Nov 9, 2010 12:17 PM, "Peter Breitsprecher" <pkbreits at lakeheadu.ca>
> wrote:
> >>
> >> As an example, I want have most of the functions for Plus, Minus already
> written.
> >>
> >> Here is the code for it.
> >>
> >> (define (plus num1 num2)
> >> (+ num1 num2))
> >>
> >> That is childs stuff...  Here is where I am having the problem, and
> please keep in mind I am new to DrRacket...
> >>
> >> If my program accepts input such as
> >> (plus 13 5)
> >>
> >> I need to parse it so that I know what it is asking for.  If It is a
> left parent, then I need to move on, if it is a right parent, move on to the
> next character, once i get to the next character I can see it is an
> alphanumeric character, but then I need to somehow read the whole word, so
> that I can store that value in a variable so that I can read the next
> number.  If the numbers are single digits, it is easy, because they are only
> one charater each and read-char works perfect, but I need something like a
> read-word, or read-number and I can't seem to figure out how to do it.
> >>
> >> So really I need to know how do I read the words when there are
> characters present, and read the whole numbers when there is a number
> present.
> >>
> >>
> >>
> >> On 9 November 2010 15:00, John Clements <clements at brinckerhoff.org>
> wrote:
> >> >
> >> >
> >> > On Nov 9, 2010, a...
> >>
> >> --
> >> Kurt Breitsprecher
> >> (807) 474-9601
> >> pkbreits at lakeheadu.ca
> >>
> >>
> >> _________________________________________________
> >>  For list-related administrative tasks:
> >>  http://lists.racket-lang.org/listinfo/users
> >
> >
> >
> > --
> > Kurt Breitsprecher
> > (807) 474-9601
> > pkbreits at lakeheadu.ca
> >
>
>


-- 
Kurt Breitsprecher
(807) 474-9601
pkbreits at lakeheadu.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101109/3fff65bd/attachment.html>

Posted on the users mailing list.