home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1991-02-18 | 5.5 KB | 181 lines |
-
- IMPLEMENTATION MODULE PRHASH;
- (*****************************************************************************)
- (* Modula-2 Hash-Tabellen *)
- (* (c) Peter Engels 1990 *)
- (*****************************************************************************)
-
- FROM PRSCAN IMPORT TokenTyp,SymbolTyp,str;
-
- FROM Str IMPORT Length,Copy,Compare;
-
- FROM SYSTEM IMPORT ADDRESS,ADR;
-
- FROM Lib IMPORT Move,HashString;
-
- FROM Storage IMPORT ALLOCATE,DEALLOCATE;
-
- CONST tablesize = 100;
-
- TYPE hashptr = POINTER TO hashentrys;
- hashentrys = RECORD
- symbol : SymbolTyp;
- value : POINTER TO str;
- next : hashptr
- END;
- indizes = [0..tablesize - 1];
- HashTables = ARRAY indizes OF hashptr;
- HashTable = POINTER TO HashTables;
-
- VAR table : HashTable;
-
- PROCEDURE InsertInHashTable (VAR token : TokenTyp);
-
- VAR help : hashptr;
- index : indizes;
-
- BEGIN
- NEW (help);
- token.length := Length (token.value);
- ALLOCATE (help^.value,token.length + 1);
- Move (ADR (token.value),help^.value,token.length);
- help^.value^ [token.length] := 0C;
- help^.symbol := token.symbol;
- index := HashString (token.value,tablesize);
- help^.next := table^ [index];
- table^ [index] := help
- END InsertInHashTable;
-
- PROCEDURE SearchInHashTable (VAR token : TokenTyp);
-
- VAR index : indizes;
- help : hashptr;
-
- BEGIN
- index := HashString (token.value,tablesize);
- help := table^ [index];
- WHILE (help # NIL) & (Compare (token.value,help^.value^) # 0) DO
- help := help^.next
- END;
- IF help # NIL THEN
- token.symbol := help^.symbol
- END
- END SearchInHashTable;
-
- PROCEDURE CreateHashTable;
-
- VAR index : indizes;
-
- BEGIN
- NEW (table);
- FOR index := MIN (indizes) TO MAX (indizes) DO
- table^ [index] := NIL
- END
- END CreateHashTable;
-
- PROCEDURE InitKeyWordTable;
-
- PROCEDURE InsertInTable (symbol : SymbolTyp;
- value : ARRAY OF CHAR);
-
- VAR token : TokenTyp;
-
- BEGIN
- token.symbol := symbol;
- Copy (token.value,value);
- InsertInHashTable (token)
- END InsertInTable;
-
- BEGIN
- CreateHashTable;
- InsertInTable (abssy,'ABS');
- InsertInTable (andsy,'AND');
- InsertInTable (arraysy,'ARRAY');
- InsertInTable (beginsy,'BEGIN');
- InsertInTable (bitsetsy,'BITSET');
- InsertInTable (booleansy,'BOOLEAN');
- InsertInTable (bysy,'BY');
- InsertInTable (capsy,'CAP');
- InsertInTable (casesy,'CASE');
- InsertInTable (cardsy,'CARD');
- InsertInTable (cardinalsy,'CARDINAL');
- InsertInTable (charsy,'CHAR');
- InsertInTable (chrsy,'CHR');
- InsertInTable (classsy,'CLASS');
- InsertInTable (constsy,'CONST');
- InsertInTable (decsy,'DEC');
- InsertInTable (defsy,'DEFINITION');
- InsertInTable (disposesy,'DISPOSE');
- InsertInTable (divsy,'DIV');
- InsertInTable (dosy,'DO');
- InsertInTable (elsesy,'ELSE');
- InsertInTable (elsifsy,'ELSIF');
- InsertInTable (endsy,'END');
- InsertInTable (exclsy,'EXCL');
- InsertInTable (exitsy,'EXIT');
- InsertInTable (exportsy,'EXPORT');
- InsertInTable (falsesy,'FALSE');
- InsertInTable (fieldofssy,'FieldOfs');
- InsertInTable (floatsy,'FLOAT');
- InsertInTable (forsy,'FOR');
- InsertInTable (forwardsy,'FORWARD');
- InsertInTable (fromsy,'FROM');
- InsertInTable (gotosy,'GOTO');
- InsertInTable (haltsy,'HALT');
- InsertInTable (highsy,'HIGH');
- InsertInTable (ifsy,'IF');
- InsertInTable (implsy,'IMPLEMENTATION');
- InsertInTable (importsy,'IMPORT');
- InsertInTable (insy,'IN');
- InsertInTable (incsy,'INC');
- InsertInTable (inclsy,'INCL');
- InsertInTable (inlinesy,'INLINE');
- InsertInTable (intsy,'INT');
- InsertInTable (integersy,'INTEGER');
- InsertInTable (labelsy,'LABEL');
- InsertInTable (longcardsy,'LONGCARD');
- InsertInTable (longintsy,'LONGINT');
- InsertInTable (longrealsy,'LONGREAL');
- InsertInTable (loopsy,'LOOP');
- InsertInTable (maxsy,'MAX');
- InsertInTable (minsy,'MIN');
- InsertInTable (modsy,'MOD');
- InsertInTable (mtasy,'MTA');
- InsertInTable (modulesy,'MODULE');
- InsertInTable (newsy,'NEW');
- InsertInTable (nilsy,'NIL');
- InsertInTable (notsy,'NOT');
- InsertInTable (nullprocsy,'NULLPROC');
- InsertInTable (oddsy,'ODD');
- InsertInTable (ofsy,'OF');
- InsertInTable (orsy,'OR');
- InsertInTable (ordsy,'ORD');
- InsertInTable (pointersy,'POINTER');
- InsertInTable (proctypsy,'PROC');
- InsertInTable (procsy,'PROCEDURE');
- InsertInTable (qualifiedsy,'QUALIFIED');
- InsertInTable (realsy,'REAL');
- InsertInTable (recordsy,'RECORD');
- InsertInTable (repeatsy,'REPEAT');
- InsertInTable (returnsy,'RETURN');
- InsertInTable (setsy,'SET');
- InsertInTable (shortaddrsy,'SHORTADR');
- InsertInTable (shortcardsy,'SHORTCARD');
- InsertInTable (shortintsy,'SHORTINT');
- InsertInTable (thensy,'THEN');
- InsertInTable (tosy,'TO');
- InsertInTable (truesy,'TRUE');
- InsertInTable (truncsy,'TRUNC');
- InsertInTable (typesy,'TYPE');
- InsertInTable (untilsy,'UNTIL');
- InsertInTable (valsy,'VAL');
- InsertInTable (varsy,'VAR');
- InsertInTable (virtualsy,'VIRTUAL');
- InsertInTable (vsizesy,'VSIZE');
- InsertInTable (whilesy,'WHILE');
- InsertInTable (withsy,'WITH');
- END InitKeyWordTable;
-
- BEGIN
- InitKeyWordTable
- END PRHASH.