Difference between revisions of "Itty Bitty Programming Language Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 53: Line 53:
 
===ibpl-IntExps->racket-integers===
 
===ibpl-IntExps->racket-integers===
  
==Eval==
+
==Interpreter==
{{RacketToImplement|eval|value?<br/>expand-environment<br/>eval-under-env|ibpl}}
+
{{RacketToImplement|interpreter|value?<br/>expand-environment<br/>evaluate|ibpl}}
  
 
<syntaxhighlight lang="racket">
 
<syntaxhighlight lang="racket">
Line 85: Line 85:
  
 
===expand-environment===
 
===expand-environment===
 +
<syntaxhighlight lang="racket">
 +
(define (expand-environment name value env)
 +
        (error 'not-yet-implemented))
 +
</syntaxhighlight>
  
 
'''Requirement:''' [https://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise-argument-error%29%29 raise-argument-error] for invalid parameters.
 
'''Requirement:''' [https://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise-argument-error%29%29 raise-argument-error] for invalid parameters.
  
===eval-under-env===
+
===evaluate===
 
 
===eval-exp===
 
 
<syntaxhighlight lang="racket">
 
<syntaxhighlight lang="racket">
(define (eval-exp e)
+
(define (evaluate exp env)
   (eval-under-env e null))
+
   (if (expression? exp)
 +
      (if (list? env)
 +
          (ensure-value?
 +
                (error 'not-yet-implemented))
 +
          (raise-argument-error 'env "list?" env))
 +
      (raise-argument-error 'exp "expression?" exp)))
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 17:22, 6 March 2023

Credit

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

Code To Use

Code To Investigate

Ast

Expression Structs

(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)

expression?

(define (expression? exp)
  (or (IdentifierExp? exp)
      (IntExp? exp)
      (AddExp? exp)
      (IfGreaterExp? exp)
      (NilExp? exp)
      (IsNilExp? exp)
      (ConsExp? exp)
      (CarOfConsExp? exp)
      (CdrOfConsExp? exp)
      (LetExp? exp)
      (FunctionExp? exp)
      (CallExp? exp)))

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

Interpreter

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

value?

IBPL expressions evaluate to Racket values. value? determines if the paramater v is a valid value.

Valid value types are cons cells, integers, closures, and the null empty list.

For a cons cell to be a valid value, its car and cdr must be valid values.

ensure-value?

(define (ensure-value? v)
  (if (value? v)
      v
      (raise-argument-error 'v "value?" 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

(define (expand-environment name value env)
        (error 'not-yet-implemented))

Requirement: raise-argument-error for invalid parameters.

evaluate

(define (evaluate exp env)
  (if (expression? exp)
      (if (list? env)
          (ensure-value? 
                 (error 'not-yet-implemented))
          (raise-argument-error 'env "list?" env))
      (raise-argument-error 'exp "expression?" exp)))

Macros

IbIfNil

IbLet*

(struct binding (name exp) #:transparent)

IbIfEq

Functions

ib-double

ib-sum-curry

ib-call-with-one

ib-map

ib-mapAddN

Testing

file: test_all.rkt Racket-logo.svg Test
source folder: src/test/racket/ibpl

note: ensure that you have removed all printing to receive credit for any assignment.