blob: 5b180f25c967b741ab37c8577eab8084fa9d0dd8 (
plain)
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
|
//
// ANTLRPtrStack.m
// ANTLR
//
// Created by Alan Condit on 6/9/10.
// Copyright 2010 Alan's MachineWorks. All rights reserved.
//
#define SUCCESS (0)
#define FAILURE (-1)
#import "ANTLRPtrStack.h"
#import "ANTLRTree.h"
/*
* Start of ANTLRPtrStack
*/
@implementation ANTLRPtrStack
+(ANTLRPtrStack *)newANTLRPtrStack
{
return [[ANTLRPtrStack alloc] init];
}
+(ANTLRPtrStack *)newANTLRPtrStack:(NSInteger)cnt
{
return [[ANTLRPtrStack alloc] initWithLen:cnt];
}
-(id)init
{
self = [super initWithLen:HASHSIZE];
if ( self != nil ) {
}
return( self );
}
-(id)initWithLen:(NSInteger)cnt
{
self = [super initWithLen:cnt];
if ( self != nil ) {
}
return( self );
}
-(void)dealloc
{
#ifdef DEBUG_DEALLOC
NSLog( @"called dealloc in ANTLRPtrStack" );
#endif
[super dealloc];
}
-(void)deleteANTLRPtrStack:(ANTLRPtrStack *)np
{
ANTLRLinkBase *tmp, *rtmp;
NSInteger idx;
if ( self.fNext != nil ) {
for( idx = 0; idx < BuffSize; idx++ ) {
tmp = ptrBuffer[idx];
while ( tmp ) {
rtmp = tmp;
tmp = [tmp getfNext];
[rtmp release];
}
}
}
}
#ifdef DONTUSENOMO
#ifdef USERDOC
/*
* HASH hash entry to get index to table
* NSInteger hash( ANTLRPtrStack *self, char *s );
*
* Inputs: NSString *s string to find
*
* Returns: NSInteger hashed value
*
* Last Revision 9/03/90
*/
#endif
-(NSInteger)hash:(NSString *)s /* form hash value for string s */
{
NSInteger hashval;
const char *tmp;
tmp = [s cStringUsingEncoding:NSASCIIStringEncoding];
for( hashval = 0; *tmp != '\0'; )
hashval += *tmp++;
LastHash = hashval % HashSize;
return( LastHash );
}
#ifdef USERDOC
/*
* LOOKUP search hashed list for entry
* id lookup:(NSString *)s;
*
* Inputs: NSString *s string to find
*
* Returns: ANTLRRuleMemo * pointer to entry
*
* Last Revision 9/03/90
*/
#endif
-(id)lookup:(NSString *)s
{
ANTLRLinkBase *np;
for( np = ptrBuffer[[self hash:s]]; np != nil; np = [np getfNext] ) {
if ( [s isEqualToString:[np getName]] ) {
return( np ); /* found it */
}
}
return( nil ); /* not found */
}
#ifdef USERDOC
/*
* INSTALL search hashed list for entry
* NSInteger install( ANTLRPtrStack *self, id sym );
*
* Inputs: ANTLRRuleMemo *sym -- symbol ptr to install
* NSInteger scope -- level to find
*
* Returns: Boolean TRUE if installed
* FALSE if already in table
*
* Last Revision 9/03/90
*/
#endif
-(id)install:(id)sym
{
ANTLRLinkBase *np;
np = [self lookup:[sym getName]];
if ( np == nil ) {
[sym setFNext:ptrBuffer[ LastHash ]];
ptrBuffer[ LastHash ] = [sym retain];
return( ptrBuffer[ LastHash ] );
}
return( nil ); /* not found */
}
#endif
-(id)getptrBufferEntry:(NSInteger)idx
{
return( ptrBuffer[idx] );
}
-(id *)getptrBuffer
{
return( ptrBuffer );
}
-(void)setptrBuffer:(id *)np
{
ptrBuffer = np;
}
#ifdef DONTUSENOMO
/*
* works only for maplist indexed not by name but by TokenNumber
*/
- (id)getName:(NSInteger)ttype
{
id np;
NSInteger aTType;
aTType = ttype % HashSize;
for( np = ptrBuffer[ttype]; np != nil; np = [np getfNext] ) {
if ( np.index == ttype ) {
return( np ); /* found it */
}
}
return( nil ); /* not found */
}
- (id)getTType:(NSString *)name
{
return [self lookup:name];
}
#endif
- (id) copyWithZone:(NSZone *)aZone
{
return [super copyWithZone:aZone];
}
@end
|