3
3
/**
4
4
* Symbol Table Type Definitions
5
5
*
6
- * This file defines the core types and interfaces for the symbol table system.
7
- * The symbol table acts as a metadata layer above the existing memory module,
8
- * storing information about symbols (variables, functions) rather than their values.
6
+ * This file defines the core types and interfaces for the enhanced symbol table system.
7
+ * Supports member expressions, enums, arrays, dictionaries, and system variable access control.
9
8
*/
10
9
11
10
/**
12
11
* Types of symbols that can be stored in the symbol table
13
12
*/
14
13
export enum SymbolType {
15
- /** System-defined variables and functions (built-in ) */
14
+ /** System-defined variables (immutable by user programs ) */
16
15
SYSTEM_VARIABLE = 'system_variable' ,
16
+
17
+ /** System-defined variables (configurable by main program, immutable by user programs) */
18
+ SYSTEM_VARIABLE_CONFIGURABLE = 'system_variable_configurable' ,
19
+
20
+ /** System-defined functions (built-in) */
17
21
SYSTEM_FUNCTION = 'system_function' ,
18
22
19
23
/** User-defined variables */
@@ -56,12 +60,75 @@ export enum DataType {
56
60
FUNCTION = 'function' ,
57
61
OBJECT = 'object' ,
58
62
ARRAY = 'array' ,
63
+ DICTIONARY = 'dictionary' ,
64
+ ENUM = 'enum' ,
65
+ PRIMITIVE_VARIABLE = 'primitive_variable' ,
59
66
UNDEFINED = 'undefined' ,
60
67
ANY = 'any' ,
61
68
}
62
69
63
70
/**
64
- * Additional metadata that can be attached to symbols
71
+ * Execution context for access control
72
+ */
73
+ export enum ExecutionContext {
74
+ /** Main program execution - can modify system configurable variables */
75
+ MAIN_PROGRAM = 'main_program' ,
76
+
77
+ /** User program execution - cannot modify system variables */
78
+ USER_PROGRAM = 'user_program' ,
79
+ }
80
+
81
+ /**
82
+ * Memory pointer to reference memory module locations
83
+ */
84
+ export interface MemoryPointer {
85
+ readonly threadId : string ;
86
+ readonly frameId : string ;
87
+ readonly variableName : string ;
88
+ }
89
+
90
+ /**
91
+ * Enum-specific metadata
92
+ */
93
+ export interface EnumMetadata {
94
+ readonly possibleValues : readonly string [ ] ;
95
+ readonly currentValue ?: string ;
96
+ readonly enumType : string ;
97
+ }
98
+
99
+ /**
100
+ * Array-specific metadata
101
+ */
102
+ export interface ArrayMetadata {
103
+ readonly elementType : DataType ;
104
+ readonly dimensions ?: number ;
105
+ readonly maxLength ?: number ;
106
+ readonly minLength ?: number ;
107
+ }
108
+
109
+ /**
110
+ * Dictionary-specific metadata
111
+ */
112
+ export interface DictionaryMetadata {
113
+ readonly keyType : DataType ;
114
+ readonly valueType : DataType ;
115
+ readonly requiredKeys ?: readonly string [ ] ;
116
+ readonly allowDynamicKeys : boolean ;
117
+ readonly maxSize ?: number ;
118
+ }
119
+
120
+ /**
121
+ * Object property metadata for member expressions
122
+ */
123
+ export interface ObjectPropertyMetadata {
124
+ readonly propertyName : string ;
125
+ readonly propertyType : DataType ;
126
+ readonly isReadOnly : boolean ;
127
+ readonly parentObject : string ;
128
+ }
129
+
130
+ /**
131
+ * Metadata that can be attached to symbols
65
132
*/
66
133
export interface SymbolMetadata {
67
134
/** When the symbol was declared */
@@ -74,6 +141,9 @@ export interface SymbolMetadata {
74
141
file ?: string ;
75
142
} ;
76
143
144
+ /** Memory pointer to memory module */
145
+ readonly memoryPointer ?: MemoryPointer ;
146
+
77
147
/** Function-specific metadata */
78
148
readonly functionMetadata ?: {
79
149
parameterCount : number ;
@@ -88,6 +158,18 @@ export interface SymbolMetadata {
88
158
defaultValue ?: unknown ;
89
159
} ;
90
160
161
+ /** Enum-specific metadata */
162
+ readonly enumMetadata ?: EnumMetadata ;
163
+
164
+ /** Array-specific metadata */
165
+ readonly arrayMetadata ?: ArrayMetadata ;
166
+
167
+ /** Dictionary-specific metadata */
168
+ readonly dictionaryMetadata ?: DictionaryMetadata ;
169
+
170
+ /** Object property metadata for member expressions */
171
+ readonly objectPropertyMetadata ?: ObjectPropertyMetadata ;
172
+
91
173
/** Additional custom metadata */
92
174
readonly [ key : string ] : unknown ;
93
175
}
@@ -96,9 +178,6 @@ export interface SymbolMetadata {
96
178
* Core symbol entry interface
97
179
*/
98
180
export interface ISymbolEntry {
99
- toPlainObject ( ) : unknown ;
100
- isFunction ( ) : any ;
101
- getFunctionMetadata ( ) : unknown ;
102
181
/** Symbol name/identifier */
103
182
readonly name : string ;
104
183
@@ -117,6 +196,9 @@ export interface ISymbolEntry {
117
196
/** Whether symbol value can be modified */
118
197
readonly isMutable : boolean ;
119
198
199
+ /** Whether symbol can be modified by user programs */
200
+ readonly isUserModifiable : boolean ;
201
+
120
202
/** Reference to memory location in the memory module */
121
203
readonly memoryLocation ?: string ;
122
204
@@ -128,6 +210,31 @@ export interface ISymbolEntry {
128
210
129
211
/** Unique identifier for this symbol entry */
130
212
readonly id : string ;
213
+
214
+ /** Methods */
215
+ withUpdates ( updates : {
216
+ memoryLocation ?: string ;
217
+ frameId ?: string ;
218
+ metadata ?: SymbolMetadata ;
219
+ } ) : ISymbolEntry ;
220
+
221
+ canBeShadowed ( ) : boolean ;
222
+ canBeModified ( ) : boolean ;
223
+ canBeModifiedByUser ( ) : boolean ;
224
+ isFunction ( ) : boolean ;
225
+ isVariable ( ) : boolean ;
226
+ isEnum ( ) : boolean ;
227
+ isArray ( ) : boolean ;
228
+ isDictionary ( ) : boolean ;
229
+ isMemberReference ( ) : boolean ;
230
+ getFunctionMetadata ( ) : SymbolMetadata [ 'functionMetadata' ] | null ;
231
+ getVariableMetadata ( ) : SymbolMetadata [ 'variableMetadata' ] | null ;
232
+ getEnumMetadata ( ) : EnumMetadata | null ;
233
+ getArrayMetadata ( ) : ArrayMetadata | null ;
234
+ getDictionaryMetadata ( ) : DictionaryMetadata | null ;
235
+ getObjectPropertyMetadata ( ) : ObjectPropertyMetadata | null ;
236
+ toPlainObject ( ) : Record < string , unknown > ;
237
+ toString ( ) : string ;
131
238
}
132
239
133
240
/**
@@ -144,6 +251,29 @@ export interface SymbolLookupResult {
144
251
readonly isInCurrentScope : boolean ;
145
252
}
146
253
254
+ /**
255
+ * Member expression resolution result
256
+ */
257
+ export interface MemberResolutionResult {
258
+ /** Parent object symbol */
259
+ readonly parentSymbol : ISymbolEntry ;
260
+
261
+ /** Property name being accessed */
262
+ readonly propertyName : string ;
263
+
264
+ /** Property type */
265
+ readonly propertyType : DataType ;
266
+
267
+ /** Whether property exists */
268
+ readonly exists : boolean ;
269
+
270
+ /** Whether property is readable */
271
+ readonly isReadable : boolean ;
272
+
273
+ /** Whether property is writable */
274
+ readonly isWritable : boolean ;
275
+ }
276
+
147
277
/**
148
278
* Symbol table interface
149
279
*/
@@ -157,12 +287,16 @@ export interface ISymbolTable<T extends object> {
157
287
isMutable ?: boolean ;
158
288
metadata ?: SymbolMetadata ;
159
289
frameId ?: string ;
290
+ executionContext ?: ExecutionContext ;
160
291
} ,
161
292
) : ISymbolEntry ;
162
293
163
294
/** Look up a symbol by name */
164
295
lookup ( name : string ) : SymbolLookupResult | null ;
165
296
297
+ /** Resolve member expression (a.b) */
298
+ resolveMember ( objectName : string , propertyName : string ) : MemberResolutionResult | null ;
299
+
166
300
/** Check if symbol exists in current scope */
167
301
existsInCurrentScope ( name : string ) : boolean ;
168
302
@@ -184,8 +318,20 @@ export interface ISymbolTable<T extends object> {
184
318
/** Get current scope depth */
185
319
getCurrentScopeDepth ( ) : number ;
186
320
187
- /** Validate symbol usage */
188
- validateSymbolUsage ( name : string , context : string ) : boolean ;
321
+ /** Validate symbol usage with access control */
322
+ validateSymbolUsage (
323
+ name : string ,
324
+ context : string ,
325
+ executionContext ?: ExecutionContext ,
326
+ ) : boolean ;
327
+
328
+ /** Validate member access */
329
+ validateMemberAccess (
330
+ objectName : string ,
331
+ propertyName : string ,
332
+ isWrite : boolean ,
333
+ executionContext ?: ExecutionContext ,
334
+ ) : boolean ;
189
335
190
336
/** Remove symbol from current scope */
191
337
removeSymbol ( name : string ) : boolean ;
@@ -207,50 +353,123 @@ export interface ISymbolResolver<T extends object> {
207
353
/** Resolve symbol name to frame ID */
208
354
resolveToFrameId ( name : string ) : string | null ;
209
355
356
+ /** Resolve member expression to memory location */
357
+ resolveMemberToMemoryLocation ( objectName : string , propertyName : string ) : string | null ;
358
+
210
359
/** Get symbol metadata */
211
360
getSymbolMetadata ( name : string ) : SymbolMetadata | null ;
212
361
213
362
/** Check if symbol is accessible from current context */
214
- isSymbolAccessible ( name : string ) : boolean ;
363
+ isSymbolAccessible ( name : string , executionContext ?: ExecutionContext ) : boolean ;
364
+
365
+ /** Check if member is accessible */
366
+ isMemberAccessible (
367
+ objectName : string ,
368
+ propertyName : string ,
369
+ executionContext ?: ExecutionContext ,
370
+ ) : boolean ;
371
+
372
+ /** Validate enum value */
373
+ validateEnumValue ( symbolName : string , value : string ) : boolean ;
374
+
375
+ /** Get enum possible values */
376
+ getEnumPossibleValues ( symbolName : string ) : readonly string [ ] | null ;
215
377
}
216
378
217
379
/**
218
- * Errors that can occur in symbol table operations
380
+ * Errors for symbol table operations
219
381
*/
220
382
export class SymbolTableError extends Error {
221
383
constructor (
222
384
message : string ,
223
385
public readonly symbolName ?: string ,
386
+ public readonly executionContext ?: ExecutionContext ,
224
387
) {
225
388
super ( message ) ;
226
389
this . name = 'SymbolTableError' ;
227
390
}
228
391
}
229
392
230
393
export class SymbolAlreadyExistsError extends SymbolTableError {
231
- constructor ( symbolName : string ) {
232
- super ( `Symbol "${ symbolName } " already exists in current scope` , symbolName ) ;
394
+ constructor ( symbolName : string , executionContext ?: ExecutionContext ) {
395
+ super (
396
+ `Symbol "${ symbolName } " already exists in current scope` ,
397
+ symbolName ,
398
+ executionContext ,
399
+ ) ;
233
400
this . name = 'SymbolAlreadyExistsError' ;
234
401
}
235
402
}
236
403
237
404
export class SymbolNotFoundError extends SymbolTableError {
238
- constructor ( symbolName : string ) {
239
- super ( `Symbol "${ symbolName } " not found` , symbolName ) ;
405
+ constructor ( symbolName : string , executionContext ?: ExecutionContext ) {
406
+ super ( `Symbol "${ symbolName } " not found` , symbolName , executionContext ) ;
240
407
this . name = 'SymbolNotFoundError' ;
241
408
}
242
409
}
243
410
244
411
export class InvalidSymbolOperationError extends SymbolTableError {
245
- constructor ( operation : string , symbolName : string , reason : string ) {
246
- super ( `Invalid ${ operation } operation on symbol "${ symbolName } ": ${ reason } ` , symbolName ) ;
412
+ constructor (
413
+ operation : string ,
414
+ symbolName : string ,
415
+ reason : string ,
416
+ executionContext ?: ExecutionContext ,
417
+ ) {
418
+ super (
419
+ `Invalid ${ operation } operation on symbol "${ symbolName } ": ${ reason } ` ,
420
+ symbolName ,
421
+ executionContext ,
422
+ ) ;
247
423
this . name = 'InvalidSymbolOperationError' ;
248
424
}
249
425
}
250
426
427
+ export class AccessControlError extends SymbolTableError {
428
+ constructor ( symbolName : string , operation : string , executionContext ?: ExecutionContext ) {
429
+ super (
430
+ `Access denied: ${ operation } operation on symbol "${ symbolName } " not allowed in ${ executionContext } context` ,
431
+ symbolName ,
432
+ executionContext ,
433
+ ) ;
434
+ this . name = 'AccessControlError' ;
435
+ }
436
+ }
437
+
438
+ export class MemberAccessError extends SymbolTableError {
439
+ constructor (
440
+ objectName : string ,
441
+ propertyName : string ,
442
+ reason : string ,
443
+ executionContext ?: ExecutionContext ,
444
+ ) {
445
+ super (
446
+ `Member access error: ${ objectName } .${ propertyName } - ${ reason } ` ,
447
+ `${ objectName } .${ propertyName } ` ,
448
+ executionContext ,
449
+ ) ;
450
+ this . name = 'MemberAccessError' ;
451
+ }
452
+ }
453
+
454
+ export class EnumValidationError extends SymbolTableError {
455
+ constructor (
456
+ symbolName : string ,
457
+ value : string ,
458
+ possibleValues : readonly string [ ] ,
459
+ executionContext ?: ExecutionContext ,
460
+ ) {
461
+ super (
462
+ `Invalid enum value "${ value } " for symbol "${ symbolName } ". Valid values: ${ possibleValues . join ( ', ' ) } ` ,
463
+ symbolName ,
464
+ executionContext ,
465
+ ) ;
466
+ this . name = 'EnumValidationError' ;
467
+ }
468
+ }
469
+
251
470
export class ScopeOperationError extends SymbolTableError {
252
- constructor ( operation : string , reason : string ) {
253
- super ( `Scope ${ operation } failed: ${ reason } ` ) ;
471
+ constructor ( operation : string , reason : string , executionContext ?: ExecutionContext ) {
472
+ super ( `Scope ${ operation } failed: ${ reason } ` , undefined , executionContext ) ;
254
473
this . name = 'ScopeOperationError' ;
255
474
}
256
475
}
0 commit comments