开发者

another scheme beginner question

开发者 https://www.devze.com 2022-12-17 23:37 出处:网络
I am following the \"Programming Languages :Application and Interpretation\" http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/plai-2007-04-26.pdf (Page 21)

I am following the "Programming Languages :Application and Interpretation"

http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/plai-2007-04-26.pdf (Page 21)

Now I am working on Page 21,with all the test cases. I could only pass the first one,while all test cases that having "with" fails开发者_如何学C.I realized that my parser doesnt have statements to cope with "with".

This is my parser at moment:

(define (parse sexp)
  (cond
    [(number? sexp)(num sexp)]
    [(list? sexp)
     (case (first sexp)
       [(+) (add (parse (second sexp))
                 (parse (third sexp)))]
       [(-) (sub (parse (second sexp))
                 (parse (third sexp)))])]))

So could you please help is it because this parse function that causes my above tests fail? Thanks.


Your parser is far from a complete one, so trying to deal with the actual implementation of with is not something that you should try yet. If you're taking this in the context of some class, you definitely need to consult the course staff. If you're trying this yourself, then you need to take things slowly and make sure you have a working parser before you get to the rest of the code.

One resource that can help you with that is my class notes, which contain an example for such parsers. (I just got to cover that exact point in the material today, btw.) But if you do use it, then you should note that it is diverging from the PLAI code in a number of aspects -- the language is a typed language, not plain scheme; the parsers that we write use match, and the whole organization of programs is slightly different. Still, it should give you a rough idea how to proceed if you're doing this on your own, and get stuck.


Actually, if you read further on,

Just when we thought we were done, we find that several of the test cases above (can you determine which ones?) generate a free-identifier error

He explains why the "with" expressions fail.

0

精彩评论

暂无评论...
验证码 换一张
取 消