@@ -76,24 +76,20 @@ Here's the AST definition for the added primitives and @racket[cond]:
7676(racketblock
7777;; type Expr =
7878;; ...
79- ;; | (Cond [Listof CondClause] Expr)
80-
81- ;; type CondClause = (Clause Expr Expr)
79+ ;; | (Cond [Listof Expr] [Listof Expr] Expr)
8280
8381;; type Op =
8482;; ...
8583;; | 'abs | '- | 'not
8684
8785(struct Cond (cs e) #:prefab )
88- (struct Clause (p b) #:prefab )
8986)
9087
9188There is one new kind of expression constructor: @racket[Cond]. A
92- @racket[Cond] AST node contains a list of cond-clauses and expression,
93- which the expression of the @racket[else ] clause. Each cond-clause is
94- represented by a @racket[Clause] structure containing two expressions:
95- the left-hand-side of the clause which is used to determine whether
96- the right-hand-side is evaluated, and the right-hand-side expression.
89+ @racket[Cond] AST node contains three parts: two equal length lists of
90+ expression and an expression. The two lists represent the clauses,
91+ where the first list contains all of the left-hand-side parts of the
92+ clauses and the other contains all of the right-hand-side parts.
9793
9894Here are some examples of how concrete expressions are parsed into
9995ASTs using this representation:
@@ -104,14 +100,14 @@ ASTs using this representation:
104100
105101@item{@racket[(not #t )] parses as @racket[(Prim1 'not (Lit #t ))],}
106102
107- @item{@racket[(cond [else 5 ])] parses as @racket[(Cond '() (Lit 5 ))],}
103+ @item{@racket[(cond [else 5 ])] parses as @racket[(Cond '() '() (Lit 5 ))],}
108104
109105@item{@racket[(cond [(not #t ) 3 ] [else 5 ])] parses as @racket[(Cond
110- (list (Clause ( Prim1 'not (Lit #t )) ( Lit 3 ) )) (Lit 5 ))],}
106+ (list (Prim1 'not (Lit #t ))) (list ( Lit 3 )) (Lit 5 ))],}
111107
112108@item{@racket[(cond [(not #t ) 3 ] [7 4 ] [else 5 ])] parses as
113- @racket[(Cond (list (Clause ( Prim1 'not (Lit #t )) (Lit 3 )) (Clause
114- (Lit 7 ) (Lit 4 ) )) (Lit 5 ))],}
109+ @racket[(Cond (list (Prim1 'not (Lit #t )) (Lit 7 )) (list (Lit 3 )
110+ (Lit 4 )) (Lit 5 ))],}
115111]
116112
117113@subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Implementing primitives}
0 commit comments