-
Notifications
You must be signed in to change notification settings - Fork 0
/
pegd-samples.rkt~
134 lines (109 loc) · 2.97 KB
/
pegd-samples.rkt~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#lang typed/racket
(require "./pegd-syntax.rkt")
(require "./pegd-derivate.rkt")
(require "./pegd-fderivate.rkt")
(require "./pegd-input-gen.rkt")
(provide (all-defined-out))
; S <- ab
(define pex0 : DPEG
(DPEG (list (cons "S" (pCat (pSym #\a) (pSym #\b) ) ))
(pVar "S"))
)
; S <- aS / Eps
(define pex1 : DPEG
(DPEG (list (cons "S" (pAlt (pCat (pSym #\a) (pVar "S") ) (pϵ) )))
(pVar "S"))
)
; S <- aSb / ϵ
(define pex2 : DPEG
(DPEG (list (cons "S" (pAlt (pCat (pSym #\a) (pCat (pVar "S") (pSym #\b))) (pϵ))))
(pVar "S"))
)
; S <- a*
(define pex3 : DPEG
(DPEG (list (cons "S" (pKle (pSym #\a))) )
(pVar "S"))
)
; A <- aA / ϵ
; B <- bB / c
; AB
(define pex4 : DPEG
(DPEG (list (cons "A" (pAlt (pCat (pSym #\a) (pVar "A")) (pϵ) ))
(cons "B" (pAlt (pCat (pSym #\b) (pVar "B")) (pSym #\c) ))
)
(pCat (pVar "A") (pVar "B" )))
)
; A<- ab*
; A
(define pex5 : DPEG
(DPEG (list (cons "A" (pCat ( pKle (pSym #\a)) (pSym #\b))))
(pVar "A"))
)
; A <- aA / ϵ
; B <- AB / BA
; AB
;(loop)
(define pex6 : DPEG
(DPEG (list (cons "A" (pAlt (pCat (pSym #\a) (pVar "A") ) (pϵ) ))
(cons "B" (pAlt (pCat (pVar "A") (pVar "B")) (pCat (pVar "B") (pVar "A")))) )
(pCat (pVar "A") (pVar "B") ))
)
; Ford's wrong An Bn Cn
; S <- !!A a* B
; A <- aAb / eps
; B <- bBc / eps
; Extended regular expressions !
(define pex7 : DPEG
(DPEG (list (cons "A" (pAlt (pCat (pCat (pSym #\a) (pVar "A") ) (pSym #\b)) (pϵ) ))
(cons "B" (pAlt (pCat (pCat (pSym #\b) (pVar "B") ) (pSym #\c)) (pϵ) )) )
(pCat (pCat (pNot (pNot (pVar "A"))) (pKle (pSym #\a))) (pVar "B") ))
)
; S <- !(ab)c
(define pex8 : DPEG
(DPEG (list (cons "S" (pCat (pNot (pCat (pSym #\a) (pSym #\b))) (pSym #\c) )))
(pVar "S"))
)
; S <- !(ab*c)c
(define pex9 : DPEG
(DPEG (list (cons "S" (pCat (pNot (pCat (pSym #\a) (pSym #\b))) (pSym #\c) )))
(pVar "S"))
)
;A <- aAb / e
;B <- bB / b
;C <- c
; A B C
(define pex10 : DPEG
(DPEG (list (cons "A" (pAlt (pCat (pCat (pSym #\a) (pVar "A")) (pSym #\b) ) (pSym #\e) ) )
(cons "B" (pAlt (pCat (pSym #\b) (pVar "B")) (pSym #\b)))
(cons "C" (pSym #\c) )
)
(pCat (pCat (pVar "A") (pVar "B")) (pVar "C")))
)
(define pex11 : DPEG
(DPEG '()
(pNot (pCat (pSym #\a) (pSym #\b)) ))
)
(define pex12 : DPEG
(DPEG '()
(pNot (pNot (pCat (pSym #\a) (pSym #\b)) )) )
)
(define pex13 : DPEG
(DPEG '()
(pCat (pNot (pCat (pSym #\a) (pSym #\b)) )
(pCat (pSym #\a) (pSym #\c) ))
)
)
(define pex14 : DPEG
(DPEG '()
(pCat (pNot (pSym #\a) )
(pCat (pSym #\a) (pSym #\c) ))
)
)
(define pex15 : DPEG
(DPEG '()
(pNot (pϵ)) )
)
(define pex16 : DPEG
(DPEG '()
(pCat (pAlt (pSym #\a) (pCat (pSym #\a) (pSym #\b) ) ) (pSym #\c) ))
)