@@ -76,24 +76,20 @@ Here's the AST definition for the added primitives and @racket[cond]:
76
76
(racketblock
77
77
;; type Expr =
78
78
;; ...
79
- ;; | (Cond [Listof CondClause] Expr)
80
-
81
- ;; type CondClause = (Clause Expr Expr)
79
+ ;; | (Cond [Listof Expr] [Listof Expr] Expr)
82
80
83
81
;; type Op =
84
82
;; ...
85
83
;; | 'abs | '- | 'not
86
84
87
85
(struct Cond (cs e) #:prefab )
88
- (struct Clause (p b) #:prefab )
89
86
)
90
87
91
88
There 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.
97
93
98
94
Here are some examples of how concrete expressions are parsed into
99
95
ASTs using this representation:
@@ -104,14 +100,14 @@ ASTs using this representation:
104
100
105
101
@item{@racket[(not #t )] parses as @racket[(Prim1 'not (Lit #t ))],}
106
102
107
- @item{@racket[(cond [else 5 ])] parses as @racket[(Cond '() (Lit 5 ))],}
103
+ @item{@racket[(cond [else 5 ])] parses as @racket[(Cond '() '() (Lit 5 ))],}
108
104
109
105
@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 ))],}
111
107
112
108
@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 ))],}
115
111
]
116
112
117
113
@subsection[#:tag-prefix "a3- " #:style 'unnumbered ]{Implementing primitives}
0 commit comments