Skip to content

Commit db5c78e

Browse files
committed
Draft of A3.
1 parent f2ea464 commit db5c78e

1 file changed

Lines changed: 93 additions & 106 deletions

File tree

www/assignments/3.scrbl

Lines changed: 93 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,49 @@
1010
@bold{Part 2 Due: Wednesday, February 28, 11:59PM}
1111

1212

13-
The goal of this assignment is to extend the parser, interpreter, and
14-
compiler with some simple unary numeric and boolean operations and two
15-
forms of control flow expressions: @racket[cond]-expressions and
16-
@racket[case]-expressions.
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.
1717

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.
1821

19-
You are given a file @tt{dupe-plus.zip} on ELMS with a starter
20-
compiler based on the @secref{Dupe} language we studied in class.
22+
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Part 1}
2123

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.
2228

23-
You are tasked with extending the language in a number of
24-
ways:
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:
2536

2637
@itemlist[
2738
@item{adding new primitive operations,}
2839
@item{adding @racket[cond], and}
2940
@item{adding @racket[case].}
3041
]
3142

32-
You may use any a86 instructions you'd like, however it is possible to
33-
complete the assignment using @racket[Cmp], @racket[Je], @racket[Jg],
34-
@racket[Jmp], @racket[Label], @racket[Mov], and @racket[Sub].
43+
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Primitives}
3544

36-
@section[#:tag-prefix "a3-" #:style 'unnumbered]{More primitives}
37-
38-
Add the following forms of expression to the language:
45+
The following new primitves are included in Dupe+:
3946

4047
@itemlist[
4148
@item{@racket[(abs _e)]: compute the absolute value of @racket[_e],}
4249
@item{@racket[(- _e)]: flips the sign of @racket[_e], i.e. compute @math{0-@racket[_e]}, and}
4350
@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].}
4451
]
4552

46-
There are many ways to implement these at the assembly level. You should try implementing
47-
these using the limited a86 instruction set.
48-
49-
To do this, you should:
50-
@itemlist[
51-
@item{Study @tt{ast.rkt} and the new forms of expression (i.e. new AST nodes)
52-
then update the comment at the top describing what the grammmar should look like.}
53-
54-
@item{Study @tt{parse.rkt} and add support for parsing these
55-
expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}
56-
57-
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}
58-
59-
@item{Make examples of these primitives and potential translations of them
60-
to assembly.}
61-
62-
@item{Update @tt{compile.rkt} to correctly compile these expressions.}
63-
64-
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
65-
]
53+
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Conditional expressions}
6654

67-
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Conditional Evaluation with Cond}
68-
69-
The Dupe language we studied included a simple form of performing
70-
conditional evaluation of sub-expressions:
71-
72-
@racketblock[
73-
(if _e0 _e1 _e2)
74-
]
75-
76-
However, in the original paper on Lisp,
77-
@link["http://jmc.stanford.edu/articles/recursive.html"]{@emph{Recursive
78-
Functions of Symbolic Expressions and Their Computation by Machine,
79-
Part I}}, John McCarthy introduced a generalization of @racket[if]
80-
called ``conditional expressions,'' which we could add to our
81-
language with the following syntax:
55+
The following new conditional form is included in Dupe+:
8256

8357
@racketblock[
8458
(cond [_e-p1 _e-a1]
@@ -101,59 +75,9 @@ does not evaluate to @racket[#f] is found, in which case, the corresponding expr
10175
@racket[cond] expression. If no such @racket[_e-pi] exists, the
10276
expression @racket[_e-an]'s value is the value of the @racket[cond].
10377

104-
@;{
105-
The formal semantics can be defined as:
106-
107-
@(define ((rewrite s) lws)
108-
(define lhs (list-ref lws 2))
109-
(define rhs (list-ref lws 3))
110-
(list "" lhs (string-append " " (symbol->string s) " ") rhs ""))
111-
112-
@(require (only-in racket add-between))
113-
@(define-syntax-rule (show-judgment name i j)
114-
(with-unquote-rewriter
115-
(lambda (lw)
116-
(build-lw (lw-e lw) (lw-line lw) (lw-line-span lw) (lw-column lw) (lw-column-span lw)))
117-
(with-compound-rewriters (['+ (rewrite '+)]
118-
['- (rewrite '–)]
119-
['= (rewrite '=)]
120-
['!= (rewrite '≠)])
121-
(apply centered
122-
(add-between
123-
(build-list (- j i)
124-
(λ (n) (begin (judgment-form-cases (list (+ n i)))
125-
(render-judgment-form name))))
126-
(hspace 4))))))
127-
128-
@(show-judgment 𝑪 0 1)
129-
@(show-judgment 𝑪 1 2)
130-
}
131-
132-
Your task is to extend Dupe with this (restricted) form of @racket[cond].
133-
134-
To do this, you should:
135-
136-
@itemlist[
137-
@item{Study @tt{ast.rkt} to add appropriate AST nodes.}
138-
@item{Extend @tt{parse.rkt} to parse such expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}
139-
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond] expressions.}
140-
141-
@item{Make examples of @racket[cond]-expressions and potential translations of them
142-
to assembly.}
143-
144-
@item{Update @tt{compile.rkt} to correctly compile @racket[cond]
145-
expressions based on your examples.}
146-
147-
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
148-
]
149-
150-
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Dispatching Evaluation with Case}
151-
78+
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Case expressions}
15279

153-
Racket has a mechanism for dispatching between a number of possible
154-
expressions based on a value, much like C's notion of a
155-
@tt{switch}-statement. This is the @racket[case]-expression, which we
156-
could add to our language with the following syntax:
80+
The following new case form is included in Dupe+:
15781

15882
@racketblock[
15983
(case _ev
@@ -162,6 +86,10 @@ could add to our language with the following syntax:
16286
[else _en])
16387
]
16488

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+
16593
The meaning of a @racket[case] expression is computed by evaluating
16694
the expression @racket[_ev] and then proceeding in order through each
16795
clause until one is found that has a datum @racket[_di] equal to
@@ -175,8 +103,65 @@ Note that each clause consists of a parenthesized list of
175103
@emph{datums}, which in the setting of Dupe means either integer or
176104
boolean literals.
177105

178-
Your task is to extend Dupe with this (restricted) form of @racket[case].
179106

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.
124+
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.
180165
To do this, you should:
181166

182167
@itemlist[
@@ -192,7 +177,7 @@ to assembly.}
192177
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
193178
]
194179

195-
@section[#:tag-prefix "a3-" #:style 'unnumbered #:tag "parse"]{A Leg Up on Parsing}
180+
@subsection[#:tag-prefix "a3-" #:style 'unnumbered #:tag "parse"]{A Leg Up on Parsing}
196181

197182
In the past, designing the AST type and structure definitions has
198183
given students some grief. Getting stuck at this point means you
@@ -294,6 +279,8 @@ write additional test cases.
294279

295280
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Submitting}
296281

297-
Submit a zip file containing your work to Gradescope. Use @tt{make
298-
submit.zip} from within the @tt{dupe-plus} directory to create a zip
299-
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

Comments
 (0)