|
1 "{ Package: 'stx:goodies/petitparser/compiler/benchmarks' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPSmalltalkGrammar subclass:#PPCSmalltalkNoopParser |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Benchmarks-Parsers' |
|
10 ! |
|
11 |
|
12 !PPCSmalltalkNoopParser methodsFor:'accessing'! |
|
13 |
|
14 startExpression |
|
15 "Make the sequence node has a method node as its parent and that the source is set." |
|
16 |
|
17 ^ ([ :stream | stream collection ] asParser and , super startExpression) map: [ :source :node | |
|
18 (RBMethodNode selector: #doIt body: node) |
|
19 source: source. |
|
20 (node statements size = 1 and: [ node temporaries isEmpty ]) |
|
21 ifTrue: [ node statements first ] |
|
22 ifFalse: [ node ] ] |
|
23 ! |
|
24 |
|
25 startMethod |
|
26 "Make sure the method node has the source code properly set." |
|
27 |
|
28 ^ ([ :stream | stream collection ] asParser and , super startMethod) |
|
29 map: [ :source :node | node source: source ] |
|
30 ! ! |
|
31 |
|
32 !PPCSmalltalkNoopParser methodsFor:'grammar'! |
|
33 |
|
34 array |
|
35 ^ super array map: [ :openNode :statementNodes :closeNode | ] |
|
36 |
|
37 "Modified: / 15-05-2015 / 08:54:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
38 ! |
|
39 |
|
40 expression |
|
41 ^ super expression map: [ :variableNodes :expressionNodes | ] |
|
42 |
|
43 "Modified: / 15-05-2015 / 08:55:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
44 ! |
|
45 |
|
46 method |
|
47 ^ super method map: [ :methodNode :bodyNode | ] |
|
48 |
|
49 "Modified (format): / 15-05-2015 / 08:55:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
50 ! |
|
51 |
|
52 methodDeclaration |
|
53 ^ super methodDeclaration ==> [ :nodes | nodes ] |
|
54 |
|
55 "Modified: / 15-05-2015 / 08:55:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
56 ! |
|
57 |
|
58 methodSequence |
|
59 ^ super methodSequence map: [ :periodNodes1 :pragmaNodes1 :periodNodes2 :tempNodes :periodNodes3 :pragmaNodes2 :periodNodes4 :statementNodes | ] |
|
60 |
|
61 "Modified: / 15-05-2015 / 08:55:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 ! |
|
63 |
|
64 parens |
|
65 ^ super parens map: [ :openToken :expressionNode :closeToken | ] |
|
66 |
|
67 "Modified: / 15-05-2015 / 08:55:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
68 ! |
|
69 |
|
70 pragma |
|
71 ^ super pragma ==> [ :nodes | nodes ] |
|
72 |
|
73 "Modified: / 15-05-2015 / 08:55:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
74 ! |
|
75 |
|
76 return |
|
77 ^ super return map: [ :token :expressionNode | ] |
|
78 |
|
79 "Modified: / 15-05-2015 / 08:55:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
80 ! |
|
81 |
|
82 sequence |
|
83 ^ super sequence map: [ :tempNodes :periodNodes :statementNodes | ] |
|
84 |
|
85 "Modified: / 15-05-2015 / 08:56:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
86 ! |
|
87 |
|
88 variable |
|
89 ^ super variable ==> [ :token | ] |
|
90 |
|
91 "Modified: / 15-05-2015 / 08:56:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 ! ! |
|
93 |
|
94 !PPCSmalltalkNoopParser methodsFor:'grammar-blocks'! |
|
95 |
|
96 block |
|
97 ^ super block map: [ :leftToken :blockNode :rightToken | ] |
|
98 |
|
99 "Modified: / 15-05-2015 / 08:56:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 ! |
|
101 |
|
102 blockArgument |
|
103 ^ super blockArgument ==> #second |
|
104 ! |
|
105 |
|
106 blockBody |
|
107 ^ super blockBody |
|
108 ==> [ :nodes | ] |
|
109 |
|
110 "Modified: / 15-05-2015 / 08:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
111 ! ! |
|
112 |
|
113 !PPCSmalltalkNoopParser methodsFor:'grammar-literals'! |
|
114 |
|
115 arrayLiteral |
|
116 ^ super arrayLiteral ==> [ :nodes | nodes ] |
|
117 |
|
118 "Modified (format): / 15-05-2015 / 08:56:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
119 ! |
|
120 |
|
121 arrayLiteralArray |
|
122 ^ super arrayLiteralArray ==> [ :nodes | nodes ] |
|
123 |
|
124 "Modified: / 15-05-2015 / 08:56:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
125 ! |
|
126 |
|
127 byteLiteral |
|
128 ^ super byteLiteral ==> [ :nodes | nodes ] |
|
129 |
|
130 "Modified: / 15-05-2015 / 08:56:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
131 ! |
|
132 |
|
133 byteLiteralArray |
|
134 ^ super byteLiteralArray ==> [ :nodes | nodes ] |
|
135 |
|
136 "Modified: / 15-05-2015 / 08:56:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
137 ! |
|
138 |
|
139 charLiteral |
|
140 ^ super charLiteral ==> [ :nodes | nodes ] |
|
141 |
|
142 "Modified: / 15-05-2015 / 08:57:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
143 ! |
|
144 |
|
145 falseLiteral |
|
146 ^ super falseLiteral ==> [ :nodes | nodes ] |
|
147 |
|
148 "Modified: / 15-05-2015 / 08:57:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
149 ! |
|
150 |
|
151 nilLiteral |
|
152 ^ super nilLiteral ==> [ :nodes | nodes ] |
|
153 |
|
154 "Modified: / 15-05-2015 / 08:57:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
155 ! |
|
156 |
|
157 numberLiteral |
|
158 ^ super numberLiteral ==> [ :nodes | nodes ] |
|
159 |
|
160 "Modified: / 15-05-2015 / 08:57:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
161 ! |
|
162 |
|
163 stringLiteral |
|
164 ^ super stringLiteral ==> [ :nodes | nodes ] |
|
165 |
|
166 "Modified: / 15-05-2015 / 08:57:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
167 ! |
|
168 |
|
169 symbolLiteral |
|
170 ^ super symbolLiteral ==> [ :nodes | nodes ] |
|
171 |
|
172 "Modified: / 15-05-2015 / 08:57:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
173 ! |
|
174 |
|
175 symbolLiteralArray |
|
176 ^ super symbolLiteralArray ==> [ :nodes | nodes ] |
|
177 |
|
178 "Modified: / 15-05-2015 / 08:57:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
179 ! |
|
180 |
|
181 trueLiteral |
|
182 ^ super trueLiteral ==> [ :nodes | nodes ] |
|
183 |
|
184 "Modified: / 15-05-2015 / 08:57:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
185 ! ! |
|
186 |
|
187 !PPCSmalltalkNoopParser methodsFor:'grammar-messages'! |
|
188 |
|
189 binaryExpression |
|
190 ^ super binaryExpression map: [ :receiverNode :messageNodes | ] |
|
191 |
|
192 "Modified: / 15-05-2015 / 08:57:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
193 ! |
|
194 |
|
195 cascadeExpression |
|
196 ^ super cascadeExpression map: [ :receiverNode :messageNodes | ] |
|
197 |
|
198 "Modified: / 15-05-2015 / 08:57:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
199 ! |
|
200 |
|
201 keywordExpression |
|
202 ^ super keywordExpression map: [ :receiveNode :messageNode | ] |
|
203 |
|
204 "Modified: / 15-05-2015 / 08:58:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
205 ! |
|
206 |
|
207 unaryExpression |
|
208 ^ super unaryExpression map: [ :receiverNode :messageNodes | ] |
|
209 |
|
210 "Modified: / 15-05-2015 / 08:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 ! ! |
|
212 |
|
213 !PPCSmalltalkNoopParser methodsFor:'private'! |
|
214 |
|
215 addStatements: aCollection into: aNode |
|
216 aCollection isNil |
|
217 ifTrue: [ ^ aNode ]. |
|
218 aCollection do: [ :each | |
|
219 each class == PPSmalltalkToken |
|
220 ifFalse: [ aNode addNode: each ] |
|
221 ifTrue: [ |
|
222 aNode statements isEmpty |
|
223 ifTrue: [ aNode addComments: each comments ] |
|
224 ifFalse: [ aNode statements last addComments: each comments ]. |
|
225 aNode periods: (aNode periods asOrderedCollection |
|
226 addLast: each start; |
|
227 yourself) ] ]. |
|
228 ^ aNode |
|
229 ! |
|
230 |
|
231 build: aNode assignment: anArray |
|
232 ^ anArray isEmpty |
|
233 ifTrue: [ aNode ] |
|
234 ifFalse: [ |
|
235 anArray reverse |
|
236 inject: aNode |
|
237 into: [ :result :each | |
|
238 RBAssignmentNode |
|
239 variable: each first |
|
240 value: result |
|
241 position: each second start ] ] |
|
242 ! |
|
243 |
|
244 build: aNode cascade: anArray |
|
245 | messages semicolons | |
|
246 ^ (anArray isNil or: [ anArray isEmpty ]) |
|
247 ifTrue: [ aNode ] |
|
248 ifFalse: [ |
|
249 messages := OrderedCollection new: anArray size + 1. |
|
250 messages addLast: aNode. |
|
251 semicolons := OrderedCollection new. |
|
252 anArray do: [ :each | |
|
253 messages addLast: (self |
|
254 build: aNode receiver |
|
255 messages: (Array with: each second)). |
|
256 semicolons addLast: each first start ]. |
|
257 RBCascadeNode messages: messages semicolons: semicolons ] |
|
258 ! |
|
259 |
|
260 build: aNode messages: anArray |
|
261 ^ (anArray isNil or: [ anArray isEmpty ]) |
|
262 ifTrue: [ aNode ] |
|
263 ifFalse: [ |
|
264 anArray |
|
265 inject: aNode |
|
266 into: [ :rec :msg | |
|
267 msg isNil |
|
268 ifTrue: [ rec ] |
|
269 ifFalse: [ |
|
270 RBMessageNode |
|
271 receiver: rec |
|
272 selectorParts: msg first |
|
273 arguments: msg second ] ] ] |
|
274 ! |
|
275 |
|
276 build: aTempCollection sequence: aStatementCollection |
|
277 | result | |
|
278 result := self |
|
279 addStatements: aStatementCollection |
|
280 into: RBSequenceNode new. |
|
281 aTempCollection isEmpty ifFalse: [ |
|
282 result |
|
283 leftBar: aTempCollection first start |
|
284 temporaries: aTempCollection second |
|
285 rightBar: aTempCollection last start ]. |
|
286 ^ result |
|
287 ! |
|
288 |
|
289 buildArray: aStatementCollection |
|
290 ^ self addStatements: aStatementCollection into: RBArrayNode new |
|
291 ! |
|
292 |
|
293 buildMethod: aMethodNode |
|
294 aMethodNode selectorParts |
|
295 do: [ :each | aMethodNode addComments: each comments ]. |
|
296 aMethodNode arguments |
|
297 do: [ :each | aMethodNode addComments: each token comments ]. |
|
298 aMethodNode pragmas do: [ :pragma | |
|
299 aMethodNode addComments: pragma comments. |
|
300 pragma selectorParts |
|
301 do: [ :each | aMethodNode addComments: each comments ]. |
|
302 pragma arguments do: [ :each | |
|
303 each isLiteralArray |
|
304 ifFalse: [ aMethodNode addComments: each token comments ] ]. |
|
305 pragma comments: nil ]. |
|
306 ^ aMethodNode |
|
307 ! |
|
308 |
|
309 buildString: aString |
|
310 (aString isEmpty or: [ aString first ~= $' or: [ aString last ~= $' ] ]) |
|
311 ifTrue: [ ^ aString ]. |
|
312 ^ (aString |
|
313 copyFrom: 2 |
|
314 to: aString size - 1) |
|
315 copyReplaceAll: '''''' |
|
316 with: '''' |
|
317 ! ! |
|
318 |
|
319 !PPCSmalltalkNoopParser methodsFor:'token'! |
|
320 |
|
321 binaryToken |
|
322 ^ super binaryToken ==> [ :token | token ] |
|
323 |
|
324 "Modified: / 15-05-2015 / 08:54:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
325 ! |
|
326 |
|
327 identifierToken |
|
328 ^ super identifierToken ==> [ :token | token ] |
|
329 |
|
330 "Modified: / 15-05-2015 / 08:54:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
331 ! |
|
332 |
|
333 keywordToken |
|
334 ^ super keywordToken ==> [ :token | token ] |
|
335 |
|
336 "Modified: / 15-05-2015 / 08:54:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
337 ! |
|
338 |
|
339 unaryToken |
|
340 ^ super unaryToken ==> [ :token | token ] |
|
341 |
|
342 "Modified: / 15-05-2015 / 08:54:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
343 ! ! |
|
344 |