55@(require "../../langs/con-plus/semantics.rkt " )
66@(require redex/pict)
77
8- @bold{Due: @elem[#:style "strike " ]{Friday, September 29 , 11:59PM}
9- Monday, October 2 , 11:59PM}
8+ @bold{Part 1 Due: Wednesday, February 21 , 11:59PM}
109
11- The goal of this assignment is to extend the parser, interpreter, and
12- compiler with some simple unary numeric and boolean operations and two
13- forms of control flow expressions: @racket[cond ]-expressions and
14- @racket[case ]-expressions.
10+ @bold{Part 2 Due: Wednesday, February 28 , 11:59PM}
1511
1612
17- You are given a file @tt{dupe-plus.zip} on ELMS with a starter
18- compiler based on the @secref{Dupe} language we studied in class.
13+ The goal of this assignment is to extend the language developed in
14+ @secref{Dupe} with some simple unary numeric and boolean operations
15+ and two forms of control flow expressions: @racket[cond ]-expressions
16+ and @racket[case ]-expressions.
1917
18+ This assignment consists of two parts. Part 1 asks you to write a
19+ number of programs in the extended language. Part 2 asks you to
20+ implement the language.
2021
21- You are tasked with extending the language in a number of
22- ways:
22+ @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Part 1 }
23+
24+ For this part of the assignment, you must write a number of programs
25+ in the Dupe+ language. These programs should be syntactically
26+ well-formed and @bold{produce a value} when evaluated, i.e. these should
27+ be programs that do not cause run-time errors.
28+
29+ This exercise will help you understand the features you will be
30+ implementing in the second part of the assignment and can be used to
31+ test your compiler. In fact, we will use the programs you write to
32+ run against a collection of existing Dupe+ compilers to see if they
33+ uncover any bugs. The more bugs you can uncover, the better.
34+
35+ The Dupe+ language extends Dupe in the follow ways:
2336
2437@itemlist[
2538@item{adding new primitive operations,}
2639@item{adding @racket[cond ], and }
2740@item{adding @racket[case ].}
2841]
2942
30- You may use any a86 instructions you'd like, however it is possible to
31- complete the assignment using @racket[Cmp], @racket[Je], @racket[Jg],
32- @racket[Jmp], @racket[Label], @racket[Mov], and @racket[Sub].
33-
34- @section[#:tag-prefix "a3- " #:style 'unnumbered ]{More primitives}
43+ @subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Primitives}
3544
36- Add the following forms of expression to the language :
45+ The following new primitves are included in Dupe+ :
3746
3847@itemlist[
3948@item{@racket[(abs _e)]: compute the absolute value of @racket[_e],}
4049@item{@racket[(- _e)]: flips the sign of @racket[_e], i.e. compute @math{0-@racket[_e]}, and }
4150@item{@racket[(not _e)]: compute the logical negation of @racket[_e]; note that the negation of @emph{any} value other than @racket[#f] is @racket[#f] and the negation of @racket[#f] is @racket[#t].}
4251]
4352
44- There are many ways to implement these at the assembly level. You should try implementing
45- these using the limited a86 instruction set.
46-
47- To do this , you should:
48- @itemlist[
49- @item{Study @tt{ast.rkt} and the new forms of expression (i.e. new AST nodes)
50- then update the comment at the top describing what the grammmar should look like.}
51-
52- @item{Study @tt{parse.rkt} and add support for parsing these
53- expressions. (See @secref[#:tag-prefixes '("a3- " )]{parse} for guidance.)}
54-
55- @item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}
56-
57- @item{Make examples of these primitives and potential translations of them
58- to assembly.}
59-
60- @item{Update @tt{compile.rkt} to correctly compile these expressions.}
61-
62- @item{Check your implementation by running the tests in @tt{test/all.rkt}.}
63- ]
64-
65- @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Conditional Evaluation with Cond}
66-
67- The Dupe language we studied included a simple form of performing
68- conditional evaluation of sub-expressions:
69-
70- @racketblock[
71- (if _e0 _e1 _e2)
72- ]
53+ @subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Conditional expressions}
7354
74- However, in the original paper on Lisp,
75- @link["http://jmc.stanford.edu/articles/recursive.html " ]{@emph{Recursive
76- Functions of Symbolic Expressions and Their Computation by Machine,
77- Part I}}, John McCarthy introduced a generalization of @racket[if ]
78- called ``conditional expressions,'' which we could add to our
79- language with the following syntax:
55+ The following new conditional form is included in Dupe+:
8056
8157@racketblock[
8258(cond [_e-p1 _e-a1]
@@ -99,59 +75,9 @@ does not evaluate to @racket[#f] is found, in which case, the corresponding expr
9975@racket[cond ] expression. If no such @racket[_e-pi] exists, the
10076expression @racket[_e-an]'s value is the value of the @racket[cond ].
10177
102- @;{
103- The formal semantics can be defined as:
104-
105- @(define ((rewrite s) lws)
106- (define lhs (list-ref lws 2 ))
107- (define rhs (list-ref lws 3 ))
108- (list "" lhs (string-append " " (symbol->string s) " " ) rhs "" ))
109-
110- @(require (only-in racket add-between))
111- @(define-syntax-rule (show-judgment name i j)
112- (with-unquote-rewriter
113- (lambda (lw)
114- (build-lw (lw-e lw) (lw-line lw) (lw-line-span lw) (lw-column lw) (lw-column-span lw)))
115- (with-compound-rewriters (['+ (rewrite '+ )]
116- ['- (rewrite '– )]
117- ['= (rewrite '= )]
118- ['!= (rewrite '≠ )])
119- (apply centered
120- (add-between
121- (build-list (- j i)
122- (λ (n) (begin (judgment-form-cases (list (+ n i)))
123- (render-judgment-form name))))
124- (hspace 4 ))))))
125-
126- @(show-judgment 𝑪 0 1 )
127- @(show-judgment 𝑪 1 2 )
128- }
129-
130- Your task is to extend Dupe with this (restricted) form of @racket[cond ].
131-
132- To do this , you should:
133-
134- @itemlist[
135- @item{Study @tt{ast.rkt} to add appropriate AST nodes.}
136- @item{Extend @tt{parse.rkt} to parse such expressions. (See @secref[#:tag-prefixes '("a3- " )]{parse} for guidance.)}
137- @item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond ] expressions.}
138-
139- @item{Make examples of @racket[cond ]-expressions and potential translations of them
140- to assembly.}
141-
142- @item{Update @tt{compile.rkt} to correctly compile @racket[cond ]
143- expressions based on your examples.}
144-
145- @item{Check your implementation by running the tests in @tt{test/all.rkt}.}
146- ]
147-
148- @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Dispatching Evaluation with Case}
149-
78+ @subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Case expressions}
15079
151- Racket has a mechanism for dispatching between a number of possible
152- expressions based on a value, much like C's notion of a
153- @tt{switch}-statement. This is the @racket[case ]-expression, which we
154- could add to our language with the following syntax:
80+ The following new case form is included in Dupe+:
15581
15682@racketblock[
15783(case _ev
@@ -160,6 +86,10 @@ could add to our language with the following syntax:
16086 [else _en])
16187]
16288
89+ The @racket[case ] expression form is a mechanism for dispatching
90+ between a number of possible expressions based on a value, much like
91+ C's notion of a @tt{switch}-statement.
92+
16393The meaning of a @racket[case ] expression is computed by evaluating
16494the expression @racket[_ev] and then proceeding in order through each
16595clause until one is found that has a datum @racket[_di] equal to
@@ -173,8 +103,65 @@ Note that each clause consists of a parenthesized list of
173103@emph{datums}, which in the setting of Dupe means either integer or
174104boolean literals.
175105
176- Your task is to extend Dupe with this (restricted) form of @racket[case ].
106+
107+ @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Part 2 }
108+
109+ For this part of the assignment, you must extend the parser,
110+ interpreter, and compiler to implement Dupe+. You are given a file
111+ @tt{dupe-plus.zip} on ELMS with a starter compiler based on the
112+ @secref{Dupe} language we studied in class.
113+
114+ You may use any a86 instructions you'd like, however it is possible to
115+ complete the assignment using @racket[Cmp], @racket[Je], @racket[Jg],
116+ @racket[Jmp], @racket[Label], @racket[Mov], and @racket[Sub].
117+
118+ @subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Implementing primitives}
119+
120+ Implement the primitives as described earlier.
121+
122+ There are many ways to implement these at the assembly level. You should try implementing
123+ these using the limited a86 instruction set.
177124
125+ To do this , you should:
126+ @itemlist[
127+ @item{Study @tt{ast.rkt} and the new forms of expression (i.e. new AST nodes)
128+ then update the comment at the top describing what the grammmar should look like.}
129+
130+ @item{Study @tt{parse.rkt} and add support for parsing these
131+ expressions. (See @secref[#:tag-prefixes '("a3- " )]{parse} for guidance.)}
132+
133+ @item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}
134+
135+ @item{Make examples of these primitives and potential translations of them
136+ to assembly.}
137+
138+ @item{Update @tt{compile.rkt} to correctly compile these expressions.}
139+
140+ @item{Check your implementation by running the tests in @tt{test/all.rkt}.}
141+ ]
142+
143+ @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Implementing cond }
144+
145+ Implement the @racket[cond ] expression form as described earlier.
146+ To do this , you should:
147+
148+ @itemlist[
149+ @item{Study @tt{ast.rkt} to add appropriate AST nodes.}
150+ @item{Extend @tt{parse.rkt} to parse such expressions. (See @secref[#:tag-prefixes '("a3- " )]{parse} for guidance.)}
151+ @item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond ] expressions.}
152+
153+ @item{Make examples of @racket[cond ]-expressions and potential translations of them
154+ to assembly.}
155+
156+ @item{Update @tt{compile.rkt} to correctly compile @racket[cond ]
157+ expressions based on your examples.}
158+
159+ @item{Check your implementation by running the tests in @tt{test/all.rkt}.}
160+ ]
161+
162+ @section[#:tag-prefix "a3- " #:style 'unnumbered ]{Implementing case }
163+
164+ Implement the @racket[case ] expression form as described earlier.
178165To do this , you should:
179166
180167@itemlist[
@@ -292,6 +279,8 @@ write additional test cases.
292279
293280@section[#:tag-prefix "a3- " #:style 'unnumbered ]{Submitting}
294281
295- Submit a zip file containing your work to Gradescope. Use @tt{make
296- submit.zip} from within the @tt{dupe-plus} directory to create a zip
297- file with the proper structure.
282+ For part 1 , submit to Gradescope a zip file containing well-formed
283+ Racket files that use the @tt{.rkt} file extension.
284+
285+ For part 2 , use @tt{make} from within the @tt{dupe-plus} directory to
286+ create a zip file containing your work and submit it to Gradescope.
0 commit comments