% ------------------------------- % Symbol Table Scott (c) 1997-99 % Symbol Table - Version 1.00CLU % ------------------------------- TSymbolTable=cluster [Frame:int] is Create, Store, Search, Enter, Leave % For optimal performance try to interpolate the amount of variables % per frames in the generic argument! TEntry=record[Key,Value:string] rep=TStack[TEntry,Frame] own outp:stream := stream$primary_output() %for debug reasons % ---------------------[ Create ]---------------------- Create = proc () returns (cvt) ret:rep ret:=rep$Create(TEntry${Key:"",Value:""}) rep$PushState(ret) return (ret) end Create % ---------------------[ Store ]----------------------- Store = proc (SymT:cvt,Key:string,Value:string) signals (SYM_Redefine(string)) Ent:TEntry rep$VRestoreState(SymT) while (true) do Ent:=rep$VPush(SymT) if Ent.Key=key then signal SYM_Redefine(string$copy(Key)) end end except when ST_VPushOverflow: rep$Push(SymT,TEntry${Key:Key,Value:Value}) end end Store % --------------------[ Search ]------------------------ Search = proc (SymT:cvt,Key:string) returns (string) signals (SYM_NotFound) Ent:TEntry rep$VReset(SymT) begin while (true) do Ent:=rep$VPop(SymT) if (Ent.Key=Key) then return (string$copy(Ent.Value)) else rep$VPop(SymT) end end signal SYM_NotFound end except when ST_NullVStack: signal SYM_NotFound end end Search % ---------------------[ Enter ]------------------------ Enter = proc (SymT:cvt) rep$PushState(SymT) end Enter % ---------------------[ Leave ]------------------------- Leave = proc (SymT:cvt) signals (SYM_NoFrame) rep$RestoreState(SymT) except when ST_NoMoreState: signal SYM_NoFrame end end Leave end TSymbolTable