Skip to content

Commit e4fbc47

Browse files
committed
Examples of parsing patterns.
1 parent 54c8d4a commit e4fbc47

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

www/assignments/8.scrbl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
@(require "../notes/ev.rkt"
77
"../notes/utils.rkt")
88

9-
109
@bold{Due: @assign-deadline[8]}
1110

11+
@(ev '(require knock-plus))
12+
1213
The goal of this assignment is to extend a compiler with new pattern
1314
matching forms for matching lists, vectors, and predicates.
1415

@@ -115,6 +116,30 @@ the name of a user defined function.
115116
[_ #f])
116117
]
117118

119+
@section[#:tag-prefix "a8-" #:style 'unnumbered]{Representing the syntax of patterns}
120+
121+
The AST of patterns is extended as follows:
122+
123+
@#reader scribble/comment-reader
124+
(racketblock
125+
;; type Pat = ...
126+
;; | (List [Listof Pat])
127+
;; | (Vect [Listof Pat])
128+
;; | (Pred Id)
129+
)
130+
131+
The parser includes a @racket[parse-pattern] function that parses a
132+
single pattern:
133+
134+
@ex[
135+
(parse-pattern 'x)
136+
(parse-pattern '(cons x y))
137+
(parse-pattern '(list x y z))
138+
(parse-pattern '(vector x y z))
139+
(parse-pattern '(? f?))
140+
]
141+
142+
118143

119144
@section[#:tag-prefix "a8-" #:style 'unnumbered]{Submitting}
120145

0 commit comments

Comments
 (0)