@@ -76,48 +76,41 @@ For that reason, let us give you a strong hint for a potential design
7676of the ASTs and examples of how parsing could work. You are not
7777required 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
9591There 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
10598Here are some examples of how concrete expressions are parsed into
10699ASTs 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
135135to 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
158145Note that only a small number of tests are given to you, so you should
0 commit comments