Difference between revisions of "Itty Bitty Programming Language Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 28: Line 28:
  
 
==Eval==
 
==Eval==
 +
{{RacketToImplement|eval|value?<br/>ensure-value?<br/>expand-environment<br/>eval-under-env|ibpl}}
 +
 +
<syntaxhighlight lang="racket">
 +
(struct closure (env function) #:transparent)
 +
</syntaxhighlight>
 
===value?===
 
===value?===
 +
IBPL expressions evaluate to Racket values.  Valid value types are cons cells, integers, closures, and the null empty list.  To be a valid value, a cons cell's car and cdr must be valid values.
 
===ensure-value?===
 
===ensure-value?===
 +
<syntaxhighlight lang="racket">
 +
(define (ensure-value? v)
 +
(if (value? v) v (error ("not a value: ~v" v))))
 +
</syntaxhighlight>
 
===lookup-value-in-environment===
 
===lookup-value-in-environment===
 
<syntaxhighlight lang="racket">
 
<syntaxhighlight lang="racket">
Line 43: Line 53:
  
 
===eval-under-env===
 
===eval-under-env===
 +
 +
===eval-exp===
 +
<syntaxhighlight lang="racket">
 +
(define (eval-exp e)
 +
  (eval-under-env e null))
 +
</syntaxhighlight>
  
 
==Macros==
 
==Macros==

Revision as of 03:29, 6 March 2023

Credit

This assignment is based on MUPL by Dan Grossman and his team at UW.

Code To Investigate

Ast

(struct IdentifierExp (name)                                           #:transparent)
(struct IntExp        (value)                                          #:transparent)
(struct AddExp        (left_exp right_exp)                             #:transparent)
(struct IfGreaterExp  (left_exp right_exp then_body_exp else_body_exp) #:transparent)
(struct NilExp        ()                                               #:transparent)
(struct IsNilExp      (exp)                                            #:transparent)
(struct ConsExp       (car_exp cdr_exp)                                #:transparent)
(struct CarOfConsExp  (cons_exp)                                       #:transparent)
(struct CdrOfConsExp  (cons_exp)                                       #:transparent)
(struct LetExp        (binding_name binding_exp body_exp)              #:transparent)
(struct FunctionExp   (name_option parameter_name body_exp)            #:transparent)
(struct CallExp       (function_exp argument_exp)                      #:transparent)

Code To Implement

Warmup

file: src/main/racket/ibpl/warmup.rkt Racket-logo.svg
functions: racket-integers->ibpl-IntExps
ibpl-IntExps->racket-integers

racket-integers->ibpl-IntExps

ibpl-IntExps->racket-integers

Eval

file: src/main/racket/ibpl/eval.rkt Racket-logo.svg
functions: value?
ensure-value?
expand-environment
eval-under-env
(struct closure (env function) #:transparent)

value?

IBPL expressions evaluate to Racket values. Valid value types are cons cells, integers, closures, and the null empty list. To be a valid value, a cons cell's car and cdr must be valid values.

ensure-value?

(define (ensure-value? v)
 (if (value? v) v (error ("not a value: ~v" v))))

lookup-value-in-environment

(struct entry (name value) #:transparent)

(define (lookup-value-in-environment env identifier-name)
  (cond [(null? env) (error "unbound identifier during evaluation" identifier-name)]
        [(equal? (entry-name (car env)) identifier-name) (entry-value (car env))]
        [#t (lookup-value-in-environment (cdr env) identifier-name)]))

expand-environment

eval-under-env

eval-exp

(define (eval-exp e)
  (eval-under-env e null))

Macros

IbIfNil

IbLet*

(struct binding (name exp) #:transparent)

IbIfEq

Functions

ib-double

ib-sum-curry

ib-call-with-one

ib-map

ib-mapAddN

Testing