author | vranyj1 |
Mon, 10 Sep 2012 09:07:46 +0000 | |
changeset 23 | 11ad79f459e6 |
parent 16 | 55254a6f8404 |
permissions | -rw-r--r-- |
1 | 1 |
"{ Package: 'stx:goodies/smaCC' }" |
2 |
||
3 |
"{ NameSpace: SmaCC }" |
|
4 |
||
5 |
SmaCCScanner subclass:#SmaCCGrammarScanner |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'SmaCC-Parser Generator' |
|
10 |
! |
|
11 |
||
12 |
SmaCCGrammarScanner comment:'SmaCCGrammarScanner is the scanner for the grammar parser' |
|
13 |
! |
|
14 |
||
15 |
||
16 |
!SmaCCGrammarScanner class methodsFor:'generated-comments'! |
|
17 |
||
18 |
scannerDefinitionComment |
|
19 |
||
20 |
"<name> : [a-zA-Z_] \w* ; |
|
21 |
<whitespace> : \s+ ; |
|
22 |
<tokenname> : \< <name> \> ; |
|
23 |
<symbolname> : <name> ; |
|
24 |
<keyword> : (\"" [^\""]* \"") + ; |
|
25 |
<comment> : \# [^\r\n]* ; |
|
26 |
<code>: \{ [^\}]+ \} ; |
|
27 |
<variablename> : \' <name> \' ; |
|
14 | 28 |
<production> : \: (\: \=)? ; |
29 |
" |
|
1 | 30 |
! ! |
31 |
||
32 |
!SmaCCGrammarScanner class methodsFor:'generated-initialization'! |
|
33 |
||
34 |
initializeKeywordMap |
|
14 | 35 |
keywordMap := Dictionary new. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
36 |
#( #(20 'error' 16) ) do:[:each | |
14 | 37 |
(keywordMap at:each first ifAbsentPut:[ Dictionary new ]) at:(each at:2) |
38 |
put:each last |
|
39 |
]. |
|
40 |
^ keywordMap |
|
1 | 41 |
! ! |
42 |
||
43 |
!SmaCCGrammarScanner class methodsFor:'public'! |
|
44 |
||
45 |
needsLineNumbers |
|
46 |
^true |
|
47 |
! ! |
|
48 |
||
49 |
!SmaCCGrammarScanner methodsFor:'generated-scanner'! |
|
50 |
||
14 | 51 |
keywordFor: aString |
52 |
^aString asUppercase |
|
53 |
! |
|
1 | 54 |
|
14 | 55 |
scan1 |
56 |
[ |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
57 |
[ |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
58 |
self step. |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
59 |
currentCharacter ~~ $" |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
60 |
] whileTrue. |
14 | 61 |
self recordMatch:#( 21 ). |
62 |
self step. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
63 |
(currentCharacter == $") |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
64 |
] whileTrue:[]. |
14 | 65 |
^ self reportLastMatch |
1 | 66 |
! |
67 |
||
68 |
scan2 |
|
14 | 69 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
70 |
(currentCharacter == $>) ifTrue:[ |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
71 |
^ self recordAndReportMatch:#( 10 ). |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
72 |
]. |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
73 |
(currentCharacter == $i) ifTrue:[ |
14 | 74 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
75 |
(currentCharacter == $d) ifTrue:[ |
14 | 76 |
^ self recordAndReportMatch:#( 4 ). |
77 |
]. |
|
78 |
^ self reportLastMatch |
|
79 |
]. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
80 |
(currentCharacter == $l) ifTrue:[ |
14 | 81 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
82 |
(currentCharacter == $e) ifTrue:[ |
14 | 83 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
84 |
(currentCharacter == $f) ifTrue:[ |
14 | 85 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
86 |
(currentCharacter == $t) ifTrue:[ |
14 | 87 |
^ self recordAndReportMatch:#( 6 ). |
88 |
]. |
|
89 |
^ self reportLastMatch |
|
90 |
]. |
|
91 |
^ self reportLastMatch |
|
92 |
]. |
|
93 |
^ self reportLastMatch |
|
94 |
]. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
95 |
(currentCharacter == $n) ifTrue:[ |
14 | 96 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
97 |
(currentCharacter == $o) ifTrue:[ |
14 | 98 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
99 |
(currentCharacter == $n) ifTrue:[ |
14 | 100 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
101 |
(currentCharacter == $a) ifTrue:[ |
14 | 102 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
103 |
(currentCharacter == $s) ifTrue:[ |
14 | 104 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
105 |
(currentCharacter == $s) ifTrue:[ |
14 | 106 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
107 |
(currentCharacter == $o) ifTrue:[ |
14 | 108 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
109 |
(currentCharacter == $c) ifTrue:[ |
14 | 110 |
^ self recordAndReportMatch:#( 3 ). |
111 |
]. |
|
112 |
^ self reportLastMatch |
|
113 |
]. |
|
114 |
^ self reportLastMatch |
|
115 |
]. |
|
116 |
^ self reportLastMatch |
|
117 |
]. |
|
118 |
^ self reportLastMatch |
|
119 |
]. |
|
120 |
^ self reportLastMatch |
|
121 |
]. |
|
122 |
^ self reportLastMatch |
|
123 |
]. |
|
124 |
^ self reportLastMatch |
|
125 |
]. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
126 |
(currentCharacter == $r) ifTrue:[ |
14 | 127 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
128 |
(currentCharacter == $i) ifTrue:[ |
14 | 129 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
130 |
(currentCharacter == $g) ifTrue:[ |
14 | 131 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
132 |
(currentCharacter == $h) ifTrue:[ |
14 | 133 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
134 |
(currentCharacter == $t) ifTrue:[ |
14 | 135 |
^ self recordAndReportMatch:#( 8 ). |
136 |
]. |
|
137 |
^ self reportLastMatch |
|
138 |
]. |
|
139 |
^ self reportLastMatch |
|
140 |
]. |
|
141 |
^ self reportLastMatch |
|
142 |
]. |
|
143 |
^ self reportLastMatch |
|
144 |
]. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
145 |
(currentCharacter == $s) ifTrue:[ |
14 | 146 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
147 |
(currentCharacter == $t) ifTrue:[ |
14 | 148 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
149 |
(currentCharacter == $a) ifTrue:[ |
14 | 150 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
151 |
(currentCharacter == $r) ifTrue:[ |
14 | 152 |
self step. |
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
153 |
(currentCharacter == $t) ifTrue:[ |
14 | 154 |
^ self recordAndReportMatch:#( 1 ). |
155 |
]. |
|
156 |
^ self reportLastMatch |
|
157 |
]. |
|
158 |
^ self reportLastMatch |
|
159 |
]. |
|
160 |
^ self reportLastMatch |
|
161 |
]. |
|
162 |
^ self reportLastMatch |
|
163 |
]. |
|
164 |
^ self reportLastMatch |
|
1 | 165 |
! |
166 |
||
167 |
scanForToken |
|
14 | 168 |
self step. |
169 |
(currentCharacter isLetter or:[ currentCharacter == $_ ]) ifTrue:[ |
|
170 |
[ |
|
171 |
self recordMatch:#( 20 ). |
|
172 |
self step. |
|
173 |
(currentCharacter isLetterOrDigit or:[ currentCharacter == $_ ]) |
|
174 |
] whileTrue. |
|
175 |
^ self reportLastMatch |
|
176 |
]. |
|
177 |
(currentCharacter isSeparator |
|
178 |
or:[ currentCharacter == (Character codePoint:16rB) ]) |
|
179 |
ifTrue:[ |
|
180 |
[ |
|
181 |
self recordMatch:#whitespace. |
|
182 |
self step. |
|
183 |
(currentCharacter isSeparator |
|
184 |
or:[ currentCharacter == (Character codePoint:16rB) ]) |
|
185 |
] whileTrue. |
|
186 |
^ self reportLastMatch |
|
187 |
]. |
|
188 |
(currentCharacter == $") ifTrue:[ |
|
189 |
^ self scan1 |
|
190 |
]. |
|
191 |
(currentCharacter == $#) ifTrue:[ |
|
192 |
[ |
|
193 |
self recordMatch:#comment. |
|
194 |
self step. |
|
195 |
(currentCharacter <= (Character tab) |
|
196 |
or:[ |
|
197 |
(currentCharacter between:(Character codePoint:16rB) |
|
198 |
and:(Character codePoint:16rC)) |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
199 |
or:[ currentCharacter >= (Character codePoint:16rE) ] |
14 | 200 |
]) |
201 |
] whileTrue. |
|
202 |
^ self reportLastMatch |
|
203 |
]. |
|
204 |
(currentCharacter == $%) ifTrue:[ |
|
205 |
^ self scan2 |
|
206 |
]. |
|
207 |
(currentCharacter == $') ifTrue:[ |
|
208 |
self step. |
|
209 |
(currentCharacter isLetter or:[ currentCharacter == $_ ]) ifTrue:[ |
|
210 |
[ |
|
211 |
self step. |
|
212 |
(currentCharacter isLetterOrDigit or:[ currentCharacter == $_ ]) |
|
213 |
] whileTrue. |
|
214 |
(currentCharacter == $') ifTrue:[ |
|
215 |
^ self recordAndReportMatch:#( 24 ). |
|
216 |
]. |
|
217 |
^ self reportLastMatch |
|
218 |
]. |
|
219 |
^ self reportLastMatch |
|
220 |
]. |
|
221 |
(currentCharacter == $() ifTrue:[ |
|
222 |
^ self recordAndReportMatch:#( 17 ). |
|
223 |
]. |
|
224 |
(currentCharacter == $)) ifTrue:[ |
|
225 |
^ self recordAndReportMatch:#( 12 ). |
|
226 |
]. |
|
227 |
(currentCharacter == $*) ifTrue:[ |
|
228 |
^ self recordAndReportMatch:#( 9 ). |
|
229 |
]. |
|
230 |
(currentCharacter == $+) ifTrue:[ |
|
231 |
^ self recordAndReportMatch:#( 15 ). |
|
232 |
]. |
|
233 |
(currentCharacter == $:) ifTrue:[ |
|
234 |
self recordMatch:#( 25 ). |
|
235 |
self step. |
|
236 |
(currentCharacter == $:) ifTrue:[ |
|
237 |
self step. |
|
238 |
(currentCharacter == $=) ifTrue:[ |
|
239 |
^ self recordAndReportMatch:#( 25 ). |
|
240 |
]. |
|
241 |
^ self reportLastMatch |
|
242 |
]. |
|
243 |
^ self reportLastMatch |
|
244 |
]. |
|
245 |
(currentCharacter == $;) ifTrue:[ |
|
246 |
^ self recordAndReportMatch:#( 7 ). |
|
247 |
]. |
|
248 |
(currentCharacter == $<) ifTrue:[ |
|
249 |
self step. |
|
250 |
(currentCharacter isLetter or:[ currentCharacter == $_ ]) ifTrue:[ |
|
251 |
[ |
|
252 |
self step. |
|
253 |
(currentCharacter isLetterOrDigit or:[ currentCharacter == $_ ]) |
|
254 |
] whileTrue. |
|
255 |
(currentCharacter == $>) ifTrue:[ |
|
256 |
^ self recordAndReportMatch:#( 19 ). |
|
257 |
]. |
|
258 |
^ self reportLastMatch |
|
259 |
]. |
|
260 |
(currentCharacter == $%) ifTrue:[ |
|
261 |
^ self recordAndReportMatch:#( 13 ). |
|
262 |
]. |
|
263 |
^ self reportLastMatch |
|
264 |
]. |
|
265 |
(currentCharacter == $?) ifTrue:[ |
|
266 |
^ self recordAndReportMatch:#( 5 ). |
|
267 |
]. |
|
268 |
(currentCharacter == $[) ifTrue:[ |
|
269 |
^ self recordAndReportMatch:#( 11 ). |
|
270 |
]. |
|
271 |
(currentCharacter == $]) ifTrue:[ |
|
272 |
^ self recordAndReportMatch:#( 14 ). |
|
273 |
]. |
|
274 |
(currentCharacter == ${) ifTrue:[ |
|
275 |
self step. |
|
16
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
276 |
(currentCharacter ~~ $}) ifTrue:[ |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
277 |
[ |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
278 |
self step. |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
279 |
currentCharacter ~~ $} |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
280 |
] whileTrue. |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
281 |
^ self recordAndReportMatch:#( 23 ) |
55254a6f8404
Generated scanners how uses Character>>is* methods on iff they
vranyj1
parents:
14
diff
changeset
|
282 |
]. |
14 | 283 |
^ self reportLastMatch |
284 |
]. |
|
285 |
(currentCharacter == $|) ifTrue:[ |
|
286 |
^ self recordAndReportMatch:#( 2 ). |
|
287 |
]. |
|
288 |
^ self reportLastMatch |
|
1 | 289 |
! ! |
290 |
||
291 |
!SmaCCGrammarScanner methodsFor:'generated-tokens'! |
|
292 |
||
293 |
emptySymbolTokenId |
|
14 | 294 |
^43 |
1 | 295 |
! |
296 |
||
297 |
errorTokenId |
|
14 | 298 |
^44 |
1 | 299 |
! ! |
300 |
||
301 |
!SmaCCGrammarScanner class methodsFor:'documentation'! |
|
302 |
||
303 |
version |
|
304 |
^ '$Header: /opt/data/cvs/stx/goodies/smaCC/SmaCC__SmaCCGrammarScanner.st,v 1.1 2006-02-09 21:15:17 vranyj1 Exp $' |
|
14 | 305 |
! |
306 |
||
307 |
version_SVN |
|
308 |
^ '$Id$' |
|
1 | 309 |
! ! |