|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCCodeGenerator subclass:#PPCTokenCodeGenerator |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Visitors' |
|
10 ! |
|
11 |
|
12 !PPCTokenCodeGenerator methodsFor:'as yet unclassified'! |
|
13 |
|
14 afterAccept: node retval: retval |
|
15 | return | |
|
16 return := super afterAccept: node retval: retval. |
|
17 return category: 'generated - tokens'. |
|
18 ^ return |
|
19 ! ! |
|
20 |
|
21 !PPCTokenCodeGenerator methodsFor:'visiting'! |
|
22 |
|
23 visitTokenNode: node |
|
24 | id startVar endVar | |
|
25 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
|
26 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
|
27 |
|
28 id := compiler idFor: node. |
|
29 compiler rememberStrategy: (PPCCompilerTokenRememberStrategy on: compiler). |
|
30 |
|
31 compiler codeAssign: 'context position + 1.' to: startVar. |
|
32 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
|
33 compiler add: 'error ifFalse: [ '. |
|
34 compiler indent. |
|
35 compiler codeAssign: 'context position.' to: endVar. |
|
36 |
|
37 compiler codeTranscriptShow: 'current token type: ', id storeString. |
|
38 compiler codeAssign: id storeString, '.' to: 'currentTokenType'. |
|
39 compiler codeAssign: node tokenClass asString, ' on: (context collection) |
|
40 start: ', startVar, ' |
|
41 stop: ', endVar, ' |
|
42 value: nil.' |
|
43 to: 'currentTokenValue := ', self retvalVar. |
|
44 compiler codeReturn. |
|
45 compiler dedent. |
|
46 compiler add: '].'. |
|
47 compiler rememberStrategy: (PPCCompilerTokenizingRememberStrategy on: compiler). |
|
48 ! |
|
49 |
|
50 visitTrimmingTokenNode: node |
|
51 | id startVar endVar | |
|
52 |
|
53 startVar := compiler allocateTemporaryVariableNamed: 'start'. |
|
54 endVar := compiler allocateTemporaryVariableNamed: 'end'. |
|
55 |
|
56 id := compiler idFor: node. |
|
57 compiler rememberStrategy: (PPCCompilerTokenRememberStrategy on: compiler). |
|
58 |
|
59 |
|
60 compiler addComment: 'Consume Whitespace:'. |
|
61 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
|
62 compiler nl. |
|
63 |
|
64 compiler codeAssign: 'context position + 1.' to: startVar. |
|
65 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: #whatever. |
|
66 |
|
67 compiler add: 'error ifFalse: [ '. |
|
68 compiler indent. |
|
69 compiler codeAssign: 'context position.' to: endVar. |
|
70 |
|
71 compiler addComment: 'Consume Whitespace:'. |
|
72 compiler codeStoreValueOf: [ self visit: node whitespace ] intoVariable: #whatever. |
|
73 compiler nl. |
|
74 |
|
75 |
|
76 compiler codeTranscriptShow: 'current token type: ', id storeString. |
|
77 compiler codeAssign: id storeString, '.' to: 'currentTokenType'. |
|
78 compiler codeAssign: node tokenClass asString, ' on: (context collection) |
|
79 start: ', startVar, ' |
|
80 stop: ', endVar, ' |
|
81 value: nil.' |
|
82 to: 'currentTokenValue := ', self retvalVar. |
|
83 compiler codeReturn. |
|
84 compiler dedent. |
|
85 compiler add: '].' . |
|
86 compiler rememberStrategy: (PPCCompilerTokenizingRememberStrategy on: compiler). |
|
87 ! ! |
|
88 |