-
Notifications
You must be signed in to change notification settings - Fork 15
/
completeRefSection.xldf
239 lines (235 loc) · 7.22 KB
/
completeRefSection.xldf
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?xml version="1.0" encoding="utf-8"?>
<xldf:sequence
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:xbgf="http://planet-sl.org/xbgf"
xmlns:xldf="http://planet-sl.org/xldf">
<!-- compose a section on refactoring transformations -->
<xldf:rename>
<from>
<title>refactoringtransformation</title>
</from>
<to>Other refactoring transformations</to>
</xldf:rename>
<xldf:place>
<section>element-massage</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:insert>
<after>
<p>
There are two expression arguments: one to be matched, and another one that
replaces the matched expression. One of them must be in a `massage relation' to
the other.
</p>
</after>
<content>
<p>The massage relation is defined as follows:</p>
<formula>(x^+)? = x^\star</formula>
<formula>(x^\star)? = x^\star</formula>
<formula>(x?)? = x?</formula>
<formula>(x^\star)^\star = x^\star</formula>
<formula>(x^+)^\star = x^\star</formula>
<formula>(x?)^\star = x^\star</formula>
<formula>(x^+)^+ = x^+</formula>
<formula>(x^\star)^+ = x^\star</formula>
<formula>(x?)^+ = x^\star</formula>
<p>The following formulae are more complicated examples of masssage:</p>
<formula>x|\varepsilon = x?</formula>
<formula>x|x = x</formula>
<formula>x^+|\varepsilon = x^\star</formula>
<formula>x^+|x? = x^\star</formula>
<formula>x x^\star = x^+</formula>
<formula>x (yx)^\star = (xy)^\star x</formula>
<formula>x (yx)^+ = (xy)^+ x</formula>
<p>Another rule that is harder to express is when</p>
<formula>x? = x</formula>
<p>in the cases when x is optional anyway, i.e. it is one of the following:</p>
<formula>\varepsilon|...</formula>
<formula>y?</formula>
<formula>y^\star</formula>
<formula>y|...</formula>
<formula>y z ...</formula>
<p>where y and z are also recursively optional anyway.</p>
</content>
</xldf:insert>
<xldf:place>
<section>element-distribute</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-factor</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:append>
<where>element-factor</where>
<content>
<p>For example,</p>
</content>
</xldf:append>
<xldf:import-grammar>
<target>element-factor</target>
<file>distribute_before.bgf</file>
</xldf:import-grammar>
<xldf:append>
<where>element-factor</where>
<content>
<p>After using this transformation:</p>
</content>
</xldf:append>
<xldf:import-sample>
<target>element-factor</target>
<file>distribute.xbnf</file>
</xldf:import-sample>
<xldf:append>
<where>element-factor</where>
<content>
<p>Will look like this:</p>
</content>
</xldf:append>
<xldf:import-grammar>
<target>element-factor</target>
<file>distribute_after.bgf</file>
</xldf:import-grammar>
<xldf:place>
<section>element-deyaccify</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:append>
<where>element-deyaccify</where>
<content>
<p>
Deyaccification uses several general patterns. Left recursion like this:
</p>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>N</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>x</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<nonterminal>y</nonterminal>
</bgf:expression>
</bgf:production>
<p>
Becomes:
</p>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>y</nonterminal>
</bgf:expression>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>x</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<p>
Right recursion like this:
</p>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>x</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>N</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<nonterminal>y</nonterminal>
</bgf:expression>
</bgf:production>
<p>
Becomes:
</p>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>x</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
<bgf:expression>
<nonterminal>y</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<p>
In either case, it is checked if x and y are the same. If they are, the result is more concise:
</p>
<bgf:production>
<nonterminal>N</nonterminal>
<bgf:expression>
<plus>
<bgf:expression>
<nonterminal>x</nonterminal>
</bgf:expression>
</plus>
</bgf:expression>
</bgf:production>
</content>
</xldf:append>
<xldf:place>
<section>element-yaccify</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-eliminate</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-introduce</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-import</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-vertical</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-horizontal</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-rename</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-rassoc</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
<xldf:place>
<section>element-lassoc</section>
<inside>group-refactoringtransformation</inside>
</xldf:place>
</xldf:sequence>