Difference between revisions of "Itty Bitty Programming Language List Converter Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
In a series of assignments, we will build the Itty Bitty Programming Language (IBPL).  The inspiration for these assignments is MUPL by Dan Grossman and his team at UW.
 
In a series of assignments, we will build the Itty Bitty Programming Language (IBPL).  The inspiration for these assignments is MUPL by Dan Grossman and his team at UW.
  
On can build an IBPL Abstract Syntax Tree (AST) with the following expressions:
+
One can build an IBPL Abstract Syntax Tree (AST) with the following expressions:
  
 
<syntaxhighlight lang="racket">
 
<syntaxhighlight lang="racket">
Line 18: Line 18:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For this exercise, we will focus on IntExp, NilExp, and ConsExp.
+
=IBPL AST Functions To Use=
 +
For this exercise, we will use on IntExp, NilExp, and ConsExp.
 +
==struct IntExp==
 +
===(IntExp v)===
 +
===(IntExp? exp)===
 +
===(IntExp-value exp)===
 +
 
 +
==struct NilExp==
 +
===(NilExp)===
 +
===(NilExp? exp)===
 +
 
 +
==struct ConsExp==
 +
===(ConsExp car_exp cdr_exp)===
 +
===(ConsExp? exp)===
 +
===(ConsExp-car_exp exp)===
 +
===(ConsExp-cdr_exp exp)===
  
 
=Racket Utilities To Use=
 
=Racket Utilities To Use=
Line 30: Line 45:
 
{{RacketToImplement|list_converter|racket-integers->ib-IntExps<br>ib-IntExps->racket-integers|ibpl/list_converter}}
 
{{RacketToImplement|list_converter|racket-integers->ib-IntExps<br>ib-IntExps->racket-integers|ibpl/list_converter}}
 
==racket-integers->ib-IntExps==
 
==racket-integers->ib-IntExps==
 +
<syntaxhighlight lang="racket">
 +
(define (racket-integers->ib-IntExps xs)
 +
        (error 'not-yet-implemented))
 +
</syntaxhighlight>
 +
 +
Convert the provided list of ints in <code>xs</code> to an IBPL AST which matches its structure.
  
 
==ib-IntExps->racket-integers==
 
==ib-IntExps->racket-integers==
 +
<syntaxhighlight lang="racket">
 +
(define (ib-IntExps->racket-integers xs)
 +
        (error 'not-yet-implemented))
 +
</syntaxhighlight>
 +
 +
Convert the provided IBPL AST consisting of ConsExps, IntExps, and NilExp in <code>xs</code> to a list of ints.
 +
 +
=Test=
 +
{{RacketUnitTest|test_list_converter|ibpl/list_converter}}

Latest revision as of 03:18, 9 November 2023

In a series of assignments, we will build the Itty Bitty Programming Language (IBPL). The inspiration for these assignments is MUPL by Dan Grossman and his team at UW.

One can build an IBPL Abstract Syntax Tree (AST) with the following expressions:

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

IBPL AST Functions To Use

For this exercise, we will use on IntExp, NilExp, and ConsExp.

struct IntExp

(IntExp v)

(IntExp? exp)

(IntExp-value exp)

struct NilExp

(NilExp)

(NilExp? exp)

struct ConsExp

(ConsExp car_exp cdr_exp)

(ConsExp? exp)

(ConsExp-car_exp exp)

(ConsExp-cdr_exp exp)

Racket Utilities To Use

Code To Implement

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

racket-integers->ib-IntExps

(define (racket-integers->ib-IntExps xs)
        (error 'not-yet-implemented))

Convert the provided list of ints in xs to an IBPL AST which matches its structure.

ib-IntExps->racket-integers

(define (ib-IntExps->racket-integers xs)
        (error 'not-yet-implemented))

Convert the provided IBPL AST consisting of ConsExps, IntExps, and NilExp in xs to a list of ints.

Test

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

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