Skip to content

Commit 7323568

Browse files
authored
Merge pull request #199 from cmsc430/fall-2025
Fall 2025
2 parents 1827584 + ccc4f1f commit 7323568

File tree

2 files changed

+35
-80
lines changed

2 files changed

+35
-80
lines changed

www/assignments/3.scrbl

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -110,66 +110,34 @@ ASTs using this representation:
110110
(Lit 4)) (Lit 5))],}
111111
]
112112

113-
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Implementing primitives}
113+
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Steps toward Dupe+}
114114

115-
Implement the primitives as described earlier.
115+
Implement the new expression forms as described earlier, both for the
116+
interpreter and compiler.
116117

117-
There are many ways to implement these at the assembly level. You should try implementing
118-
these using the limited a86 instruction set.
119-
120-
To do this, you should:
121-
@itemlist[
122-
@item{Study @tt{ast.rkt} to understand how these new forms of expression are represented.}
123-
124-
@item{Study @tt{parse.rkt} and add support for parsing these
125-
expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}
126-
127-
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}
128-
129-
@item{Make examples of these primitives and potential translations of them
130-
to assembly.}
131-
132-
@item{Update @tt{compile.rkt} to correctly compile these expressions.}
133-
134-
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
135-
]
136-
137-
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Implementing cond}
138-
139-
Implement the @racket[cond] expression form as described earlier.
140118
To do this, you should:
141119

142120
@itemlist[
143121
@item{Study @tt{ast.rkt} to understand how these new forms of
144122
expression are represented.}
145123

146-
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond] expressions.}
147-
148-
@item{Make examples of @racket[cond]-expressions and potential translations of them
149-
to assembly.}
150-
151-
@item{Update @tt{compile.rkt} to correctly compile @racket[cond]
152-
expressions based on your examples.}
124+
@item{Add test cases to @tt{test/test-runner.rkt}. These will be
125+
tested with both the interpreter and compiler.}
153126

154-
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
155-
]
156-
157-
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Testing}
127+
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly
128+
interpret @racket[cond] expressions and new primitives.}
158129

159-
You can test your code in several ways:
130+
@item{Test your interpreter with @tt{raco test test/interp.rkt}.}
160131

161-
@itemlist[
132+
@item{Make examples of @racket[cond]-expressions and primitives and
133+
potential translations of them to assembly.}
162134

163-
@item{Using the command line @tt{raco test .} from
164-
the directory containing the repository to test everything.}
135+
@item{Update @tt{compile.rkt} and @tt{compile-prim.rkt} to correctly
136+
compile these expressions based on your examples.}
165137

166-
@item{Using the command line @tt{raco test <file>} to
167-
test only @tt{<file>}.}
138+
@item{Test your compiler with @tt{raco test test/compile.rkt}.}
168139
]
169140

170-
Note that only a small number of tests are given to you, so you should
171-
write additional test cases.
172-
173141
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Submitting}
174142

175143
To submit, use @tt{make} from within the @tt{dupe-plus} directory to

www/assignments/4.scrbl

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,41 @@ For that reason, let us give you a strong hint for a potential design
7676
of the ASTs and examples of how parsing could work. You are not
7777
required to follow this design, but you certainly may.
7878

79-
Here's a potential AST definition for the added primitives,
80-
@racket[cond], and @racket[case]:
79+
Here's the AST definition for @racket[case]:
8180

8281
@#reader scribble/comment-reader
8382
(racketblock
84-
;; type Expr =
85-
;; ...
86-
;; | (Case Expr [Listof CaseClause] Expr)
87-
88-
;; type CaseClause = (Clause [Listof Datum] Expr)
83+
;; type Expr = ...
84+
;; | (Case Expr [Listof [Listof Datum]] [Listof Expr] Expr)
8985

9086
;; type Datum = Integer | Boolean
9187

92-
(struct Case (e cs el) #:prefab)
88+
(struct Case (e ds cs el) #:prefab)
9389
)
9490

9591
There is one new kind of expression constructor: @racket[Case]. A
96-
@racket[Case] AST node contains three things: an expression that is
97-
the subject of the dispatch (i.e. the expression that is evaluated to
98-
determine which clause should be taken), a list of case-clauses (not
99-
to be confused with cond-clauses), and an @racket[else]-clause
100-
expression. Each case-clause, like a cond-clause, consists of two
101-
things. Hence we re-use the @racket[Clause] structure, but with
102-
different types of elements. The first element is a list of
103-
@emph{datums}, each being either an integer or a boolean.
92+
@racket[Case] AST node contains four things: an expression that is the
93+
subject of the dispatch (i.e. the expression that is evaluated to
94+
determine which clause should be taken), a list of lists of datums, an
95+
equal length list of expressions, and an @racket[else]-clause
96+
expression. A @emph{datum} is either an integer or a boolean.
10497

10598
Here are some examples of how concrete expressions are parsed into
10699
ASTs using this representation:
107100

108101
@itemlist[
109102

110103
@item{@racket[(case (add1 3) [else 2])] parses as @racket[(Case (Prim1
111-
'add1 (Lit 3)) '() (Lit 2))].}
104+
'add1 (Lit 3)) '() '() (Lit 2))].}
112105

113106
@item{@racket[(case 4 [(4) 1] [else 2])] parses as @racket[(Case (Lit
114-
4) (list (Clause (list 4) (Lit 1))) (Lit 2))],}
107+
4) (list (list 4)) (list (Lit 1)) (Lit 2))],}
115108

116109
@item{@racket[(case 4 [(4 5 6) 1] [else 2])] parses as @racket[(Case (Lit
117-
4) (list (Clause (list 4 5 6) (Lit 1))) (Lit 2))], and}
110+
4) (list (list 4 5 6)) (list (Lit 1)) (Lit 2))], and}
118111

119112
@item{@racket[(case 4 [(4 5 6) 1] [(#t #f) 7] [else 2])] parses as @racket[(Case (Lit
120-
4) (list (Clause (list 4 5 6) (Lit 1)) (Clause (list #t #f) (Lit 7))) (Lit 2))].}
113+
4) (list (list 4 5 6) (list #t #f)) (list (Lit 1) (Lit 7)) (Lit 2))].}
121114
]
122115

123116

@@ -129,30 +122,24 @@ To do this, you should:
129122
@itemlist[
130123
@item{Study @tt{ast.rkt} to understand how this new form of expression is represented.}
131124

125+
@item{Add test cases to @tt{test/test-runner.rkt}. These will be
126+
tested with both the interpreter and compiler.}
127+
132128
@item{Update @tt{interp.rkt} to correctly interpret @racket[case] expressions.}
133129

130+
@item{Bring forward all of the changes you made to the interpreter from @secref{a3-dupe-plus}.}
131+
132+
@item{Test your interpreter with @tt{raco test test/interp.rkt}.}
133+
134134
@item{Make examples of @racket[case]-expressions and potential translations of them
135135
to assembly.}
136136

137137
@item{Update @tt{compile.rkt} to correctly compile @racket[case] expressions based on your examples.}
138138

139-
@item{Bring forward all the changes you made for @secref{a3-dupe-plus}.}
140-
141-
@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
142-
]
143-
144-
145-
@section[#:tag-prefix "a4-" #:style 'unnumbered]{Testing}
146-
147-
You can test your code in several ways:
148-
149-
@itemlist[
139+
@item{Bring forward all of the changes you made to the compiler from @secref{a3-dupe-plus}.}
150140

151-
@item{Using the command line @tt{raco test .} from
152-
the directory containing the repository to test everything.}
141+
@item{Test your interpreter with @tt{raco test test/compile.rkt}.}
153142

154-
@item{Using the command line @tt{raco test <file>} to
155-
test only @tt{<file>}.}
156143
]
157144

158145
Note that only a small number of tests are given to you, so you should

0 commit comments

Comments
 (0)