Here are some hints on 1.31:
<exp> ::= <varref> | (if <exp> <exp> <exp>) | (lambda ({<var>}*) <exp>) | ({<exp>}+)
An example of how to write Scheme code from a BNF is here
;;; syntax functions for if
(define is-if? (lambda (lst) (eq? (car lst) 'if)))
(define if-test (lambda (lst) (cadr lst)))
(define if-true (lambda (lst) (caddr lst)))
(define if-else (lambda (lst) (cadddr lst)))
;;; test if syntax functions
(is-if? '(if test true else))
(if-test '(if test true else))
(if-true '(if test true else))
(if-else '(if test true else))
;;; syntax function for lambda
(define is-lambda? (lambda (lst) (eq? (car lst) 'lambda)))
(define lambda-vars (lambda (lst) (cadr lst)))
(define lambda-body (lambda (lst) (caddr lst)))
;;; test lambda syntax functions
(is-lambda? '(lambda (vars) body))
(lambda-vars '(lambda (vars) body))
(lambda-body '(lambda (vars) body))
(mk-var-ref 'b '((a b) () (c d e) (a b f))) ==> (b : 0 1)
(mk-var-ref 'c '((a b) () (c d e) (a b f))) ==> (c : 2 0)
(mk-var-ref 'f '((a b) () (c d e) (a b f))) ==> (f : 3 2)
(mk-var-ref 'z '((a b) () (c d e) (a b f))) ==> (z free)
(define lexical-address-aux
(lambda (exp env)
(cond ((null? exp) ?)
((symbol? exp) ?)
((is-if? exp) ?)
((is-lambda? exp) ?)
(else ?))))
If there are problems with this page, please send mail to <cs330ta@cs.byu.edu>
If you have a comment about the class, please send mail to <seamons@cs.byu.edu>
© 1994-2009, Phillip J. Windley and
Bryan S. Morse. All rights reserved.
Reproduction of all or part of this work is permitted for educational or research use provided
that this copyright notice is included in any copy.
Last updated at 3:24 pm on Friday, January 31, 2003.