home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / misc / reserve.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  22.6 KB  |  722 lines

  1.  
  2. --reserve_word_hash_pkg_.ada
  3. --::::::::::
  4. -------- SIMTEL20 Ada Software Repository Prologue ------------
  5. --                                                           -*
  6. -- Unit name    : Ada Reserved Word Hash
  7. -- Version      : 1.0
  8. -- Authors      : Mars J. Gralia
  9. --              : Jerry L. Kashtan
  10. --              : The Johns Hopkins Universtity
  11. --              : Laurel, Maryland  20707
  12. -- DDN Address  : GRALIA @ APLVAX
  13. -- Copyright    : (c) 1986 Mars J. Gralia and Jerry L. Kashtan
  14. -- Date created :  November 16, 1985
  15. -- Release date :  January 29, 1986
  16. -- Last update  :  January 29, 1986
  17. -- Machine/System Compiled/Run on : DEC 8600 Cluster, DEC Ada v1.0-7
  18. --                                                           -*
  19. ---------------------------------------------------------------
  20. --                                                           -*
  21. -- Keywords     :  ADA RESERVED WORDS
  22. ----------------:  PARSER,TOKEN,TOKENIZER,SYNTAX,HASH
  23. --
  24. -- Abstract     :  This package contains the single function
  25. ----------------:  "is_Ada_reserved_word".  It returns with 
  26. ----------------:  either a "true" or "false" to the statement
  27. ----------------:  "the input character string is a reserved
  28. ----------------:  word in the Ada language."   
  29. ----------------:  The contribution of the function is that it
  30. ----------------:  executes very quickly.  It is an implemen-
  31. ----------------:  tation of the algorithm defined by David
  32. ----------------:  Wolverton in "A Perfect Hash Function for
  33. ----------------:  Ada Reserved Words", as published in
  34. ----------------:  Ada Letters, July-August 1984.
  35. --                                                           -*
  36. ------------------ Revision history ---------------------------
  37. --                                                           -*
  38. -- DATE         VERSION    AUTHOR                  HISTORY
  39. -- 1/29/86      1.0    Gralia & Kashtan    Initial Release
  40. --                                                           -*
  41. ------------------ Distribution and Copyright -----------------
  42. --                                                           -*
  43. -- This prologue must be included in all copies of this software.
  44. --
  45. -- This software is copyright by the authors.
  46. --
  47. -- This software is released to the Ada community.
  48. --
  49. -- Restrictions on use or distribution:  NONE
  50. --                                                           -*
  51. ------------------ Disclaimer ---------------------------------
  52. --                                                           -*
  53. -- This software and its documentation are provided "AS IS" and
  54. -- without any expressed or implied warranties whatsoever.
  55. -- No warranties as to performance, merchantability, or fitness
  56. -- for a particular purpose exist.
  57. --
  58. -- Because of the diversity of conditions and hardware under
  59. -- which this software may be used, no warranty of fitness for
  60. -- a particular purpose is offered.  The user is advised to
  61. -- test the software thoroughly before relying on it.  The user
  62. -- must assume the entire risk and liability of using this
  63. -- software.
  64. --
  65. -- In no event shall any person or organization of people be
  66. -- held responsible for any direct, indirect, consequential
  67. -- or inconsequential damages or lost profits.
  68. --                                                           -*
  69. -------------------END-PROLOGUE--------------------------------
  70.  
  71. --------------------------------------------------------------------------------
  72. --    R E S E R V E _ W O R D _ H A S H _ P K G                               --
  73. --                                                                            --
  74. --                                P A C K A G E   S P E C I F I C A T I O N   --
  75. --------------------------------------------------------------------------------
  76.  
  77.  
  78. PACKAGE reserve_word_hash_pkg IS
  79.  
  80.     --| OVERVIEW
  81.     --| This package contains only one subunit, a function named
  82.     --| "is_Ada_reserved_word".  It returns with either "true" or "false",
  83.     --| to the statement "the input character string is an Ada reserved word".
  84.     --|
  85.     --| The contribution of the function is that it executes very quickly.
  86.     --| It is an implementation of the algorithm defined by David Alan
  87.     --| Wolverton in "A Perfect Hash Function for Ada Reserved Words",
  88.     --| as published in the ACM's "Ada Letters", vol IV, number 1,
  89.     --| (40-44), July-August 1984.
  90.     --|
  91.     --| This was written by Mars Gralia and Jerry Kashtan, JHU, 1/24/86.
  92.     --|
  93.  
  94.  
  95.   SUBTYPE id_type IS STRING;
  96.   SUBTYPE id_length_type IS INTEGER;
  97.     --| NOTE
  98.     --| The size is unlimited to simplify caller code.  A range 
  99.     --| of 2..9 is checked inside the package.  If the length is
  100.     --| outside this range, then it is clearly FALSE that this
  101.     --| "is_Ada_reserved_word".
  102.  
  103.   FUNCTION is_Ada_reserved_word
  104.     (
  105.      input_id  : IN id_type;        -- Possible Ada reserved word
  106.      id_length : IN id_length_type  -- Logical length of "input_id"
  107.      )
  108.     RETURN BOOLEAN;
  109.  
  110.     --| OVERVIEW
  111.     --| The function "is_Ada_reserved_word" has two inputs, a (fixed length)
  112.     --| character string (input_id) and an integer (id_length).
  113.     --| The character string normally contains either an Ada reserved
  114.     --| word (LRM 2.9) or some other Ada identifier (LRM 2.3).
  115.     --| The function returns either a "true" or "false" to the statement
  116.     --| "input_id(1..id_length) is an Ada reserved word".
  117.     --|
  118.     --| The contribution of the function is that it executes very quickly.
  119.     --| It is an implementation of the algorithm defined by David Alan
  120.     --| Wolverton in "A Perfect Hash Function for Ada Reserved Words",
  121.     --| as published in the ACM's "Ada Letters", vol IV, number 1,
  122.     --| (40-44), July-August 1984.
  123.     --|
  124.     --| It was written by Mars Gralia and Jerry Kashtan of The Johns
  125.     --| Hopkins University on 1/24/86.  The system was DEC Ada v1.0-7.
  126.  
  127.     --| EFFECTS
  128.     --| See description above in "Overview".
  129.  
  130.     --| REQUIRES
  131.     --| The input string "input_id" is to be tested for the existence
  132.     --| of an Ada reserved word.  It is typically an identifier, as obtained
  133.     --| by a lexical analyzer processing an Ada program or PDL.
  134.     --| The input integer "id_length" specifies how much of the "input_id"
  135.     --| string is to be considered as a possible reserved word.  That is,
  136.     --| only the slice  input_id(1..id_length)  is considered as a possible
  137.     --| reserved word.
  138.  
  139.     --| RAISES
  140.     --| No exceptions are normally raised by the package.  Any exceptions
  141.     --| which *do* occur are due to a design, coding or compiler bug.
  142.  
  143.     --| MODIFIES
  144.     --| This package references no global data and therefore modifies none.
  145.  
  146.     --| ERRORS
  147.     --| No errors are logically possible; the input string is either a
  148.     --| reserved word or it is not.
  149.  
  150.  
  151.  
  152. END reserve_word_hash_pkg;
  153. --::::::::::
  154. --reserve_word_hash_pkg.ada
  155. --::::::::::
  156. --------------------------------------------------------------------------------
  157. --    R E S E R V E _ W O R D _ H A S H _ P K G                               --
  158. --                                                                            --
  159. --                                                  P A C K A G E   B O D Y   --
  160. --------------------------------------------------------------------------------
  161.  
  162. --  This was written by Mars Gralia and Jerry Kashtan
  163. --    of The Johns Hopkins University on 1/24/86.
  164.  
  165.  
  166.  
  167. PACKAGE BODY reserve_word_hash_pkg IS
  168.  
  169.         -- An aside: I had wanted to name this "reserveD_word_hash_pkg",
  170.         -- but that caused an internal error in DEC Ada v1.0-7!
  171.  
  172.  
  173.   SUBTYPE hash_component_type IS INTEGER RANGE -38 .. +56;
  174.     --| NOTE
  175.     --| The range here is the min and max of the individual components of
  176.     --| the hashing function.  Reference: "procedure calc_hash_vector",
  177.     --| table "char_value_array".
  178.  
  179.   SUBTYPE hash_type IS INTEGER RANGE -76 .. +171;
  180.     --| NOTE
  181.     --| The range here is the min and max values the hashing function
  182.     --| can produce.  It is calculated as follows:
  183.     --| -38 <= xlate_first <= +56
  184.     --| -38-38 <= xlate_first+xlate_last <= +56+56
  185.     --| -76-0  <= xlate_first+xlate_last+2*second_to_last <= +112+(2*25)
  186.     --| -76+2  <= xlate_first+xlate_last+2*second_to_last+length <= +162+9
  187.  
  188.   xlate_first,  
  189.   xlate_last,  
  190.   second_to_last    : hash_component_type;
  191.   hash_value        : hash_type;
  192.  
  193.  
  194.  
  195.   FUNCTION is_Ada_reserved_word
  196.     (
  197.      input_id     : IN id_type;
  198.      id_length    : IN id_length_type
  199.     ) RETURN BOOLEAN IS
  200.  
  201.     identifier : id_type (1..id_length);   -- Lower-case version of "input_id"
  202.     --| NOTE
  203.     --| This is fixed to be that of the suspected reserved word.
  204.     --| We therefore don't need to specify its length explicitly.  That
  205.     --| is, henceforth "id_length" is effectively a "global variable".
  206.  
  207. PRAGMA PAGE;
  208.  
  209.  
  210.  
  211.   --| NOTE
  212.   --|   Using "PRAGMA INLINE" just might help thing execute faster.
  213.   --|   The DEC v1.0-7 compiler refused to allow the following two
  214.   --|   routines to be "inline", so I removed them:
  215.   --|        PROCEDURE calc_hash_vector
  216.   --|        FUNCTION  identifier_matches_hash
  217.  
  218.  
  219.   FUNCTION is_alphabetic (c : CHARACTER) RETURN BOOLEAN;
  220.  
  221.   FUNCTION convert_to_lowercase (c : CHARACTER) RETURN CHARACTER;
  222.  
  223.  
  224.  
  225.   PRAGMA INLINE (
  226.     is_alphabetic,
  227.     convert_to_lowercase
  228.   );
  229.  
  230. PRAGMA PAGE;
  231.  
  232.  
  233.     
  234.     FUNCTION is_alphabetic (c : CHARACTER) RETURN BOOLEAN IS
  235.     BEGIN   -- is_alphabetic
  236.       IF (c IN 'a' .. 'z')
  237.         OR ELSE (c in 'A' .. 'Z') THEN
  238.       RETURN TRUE;
  239.       ELSE
  240.     RETURN FALSE;
  241.       END IF;
  242.     END is_alphabetic;
  243.  
  244.  
  245.     FUNCTION convert_to_lowercase (c : CHARACTER) RETURN CHARACTER IS
  246.       conversion_factor : CONSTANT INTEGER
  247.         := CHARACTER'POS('a') - CHARACTER'POS('A');
  248.     BEGIN   -- convert_to_lowercase
  249.       IF c IN 'a' .. 'z' THEN
  250.         RETURN c;
  251.       ELSE
  252.     RETURN CHARACTER'VAL ((CHARACTER'POS(c)) + conversion_factor);
  253.       END IF;
  254.     END convert_to_lowercase;
  255.   
  256.  
  257.   PROCEDURE calc_hash_vector 
  258.     ( 
  259.      token          : IN id_type; 
  260.      xlate_first,
  261.      xlate_last,
  262.      second_to_last : OUT hash_component_type
  263.     ) IS
  264.     --| OVERVIEW
  265.     --| Given a string, compute the components of its hash function.
  266.  
  267.       SUBTYPE lc_chars IS CHARACTER RANGE 'a' .. 'z';
  268.       char_value_array : CONSTANT ARRAY (lc_chars) OF hash_component_type
  269.     --| NOTE
  270.     --| This is called "XLATE array" in the paper.
  271.     := 
  272.  
  273.          ('a' =>  0,  'b' => 49,  'c' =>   0,  'd' =>  -7,  'e' => -20,
  274.           'f' => 18,  'g' => -2,  'h' => -38,  'i' =>  33,  'j' =>   0, 
  275.           'k' => -9,  'l' =>  9,  'm' =>  29,  'n' =>  -9,  'o' =>   6,
  276.           'p' => 26,  'q' =>  0,  'r' =>   8,  's' =>   1,  't' =>   1,
  277.           'u' => -9,  'v' =>  0,  'w' =>  56,  'x' => -28,  'y' =>  11,
  278.           'z' =>  0);
  279.  
  280.       BEGIN   -- calc_hash_vector procedure
  281.  
  282.         xlate_first    := char_value_array (token(1));
  283.         xlate_last     := char_value_array (token (token'LENGTH));
  284.         second_to_last := CHARACTER'POS(token(token'LENGTH - 1)) - 
  285.                                CHARACTER'POS('a');
  286.  
  287.     END calc_hash_vector;
  288.   
  289.  
  290.   FUNCTION identifier_matches_hash
  291.     (
  292.      hash_value   : IN hash_type;
  293.      identifier   : IN id_type;
  294.      id_length    : IN id_length_type
  295.     )  RETURN BOOLEAN IS
  296.  
  297.     --| OVERVIEW
  298.     --| We know the hash_value for our string, and its (probably) the
  299.     --| same as the hash value for the reserved word.  This routine
  300.     --| answers true/false to "the indicated hash_value/identifier
  301.     --| correspond to the proper Ada reserved word".
  302.  
  303.     --| NOTE
  304.     --| At one time, there was some concern that this function might
  305.     --| return the improper value.  That can't happen, according to
  306.     --| our analysis.  The reason, in general, is that the surrounding
  307.     --| algorithm and the constraints prohibit it.  In particular:
  308.     --| a) The body of the "is_Ada_reserved_word" function will continue
  309.     --| to process only strings which contain "is_alphabetic" characters.
  310.     --| b) If the first letter of a proposed reserved word were a blank,
  311.     --| then "calc_hash_vector" would give a constraint error since the
  312.     --| index to its table must be a "lower case character" in the
  313.     --| range 'a' .. 'z'.
  314.  
  315.     hash_table : CONSTANT ARRAY (0..71) OF STRING (1..9) :=
  316.  
  317.       (0 => "else     ",  1 =>  "exit     ",  2 =>  "end      ",
  318.        3 => "at       ",  4 =>  "then     ",  5 =>  "range    ",
  319.        6 => "abs      ",  7 =>  "do       ",  8 =>  "exception",
  320.        9 => "delay    ",  10 => "use      ",  11 => "xor      ",
  321.       12 => "select   ",  13 => "         ",  14 => "declare  ",
  322.       15 => "type     ",  16 => "array    ",  17 => "limited  ",
  323.       18 => "subtype  ",  19 => "elsif    ",  20 => "case     ",
  324.       21 => "generic  ",  22 => "and      ",  23 => "not      ",
  325.       24 => "renames  ",  25 => "package  ",  26 => "null     ",
  326.       27 => "separate ",  28 => "terminate",  29 => "raise    ",
  327.       30 => "entry    ",  31 => "reverse  ",  32 => "task     ",
  328.       33 => "         ",  34 => "all      ",  35 => "constant ",
  329.       36 => "delta    ",  37 => "accept   ",  38 => "digits   ",
  330.       39 => "return   ",  40 => "abort    ",  41 => "record   ",
  331.       42 => "in       ",  43 => "access   ",  44 => "or       ",
  332.       45 => "function ",  46 => "goto     ",  47 => "others   ",
  333.       48 => "rem      ",  49 => "procedure",  50 => "out      ",
  334.       51 => "private  ",  52 => "is       ",  53 => "mod      ",
  335.       54 => "of       ",  55 => "         ",  56 => "pragma   ",
  336.       57 => "for      ",  58 => "new      ",  59 => "when     ",
  337.       60 => "with     ",  61 => "begin    ",  62 => "         ",
  338.       63 => "while    ",  64 => "         ",  65 => "         ",
  339.       66 => "         ",  67 => "loop     ",  68 => "         ",
  340.       69 => "if       ",  70 => "body     ",  71 => "         ");
  341.  
  342.     table_value : STRING (1..9);
  343.  
  344.     BEGIN   -- identifier_matches_hash function
  345.  
  346.       IF hash_value NOT IN hash_table'RANGE THEN
  347.         RETURN FALSE;
  348.       END IF;
  349.  
  350.       table_value := hash_table (hash_value);
  351.  
  352.       IF table_value (1..id_length) = identifier (1..id_length) THEN
  353.         RETURN (TRUE);
  354.       ELSE
  355.         RETURN (FALSE);
  356.       END IF;
  357.   
  358.   END identifier_matches_hash;
  359.  
  360.  
  361.     
  362.     BEGIN   -- is_Ada_reserved_word
  363.         -- (main procedure of package RESERVE_WORD_HASH_PKG)
  364.  
  365.       -- Ada reserved words are 2..9 characters in length.  All other tokens --|
  366.       -- are not Ada reserved words.                         --|
  367.       IF ( (id_length > 9) OR ELSE (id_length < 2) ) THEN
  368.         --| NOTE
  369.         --| "or else" because that usually generates faster code on
  370.         --| compilers with simple optimizers.
  371.     RETURN (FALSE);
  372.       END IF;
  373.  
  374.       -- See if input characters legal and, if so, convert to lower case     --|
  375.       FOR j in 1 .. id_length LOOP
  376.  
  377.     IF NOT is_alphabetic(input_id(j)) THEN
  378.       RETURN FALSE;    -- Reserved words have alphabetic characters only    --|
  379.     END IF;
  380.  
  381.         identifier(j) := convert_to_lowercase(input_id(j));
  382.  
  383.       END LOOP;
  384.  
  385.   
  386.       --  Compute the hash function value.                     --|
  387.  
  388.       --  Translate token characters into numeric values for the 
  389.       --  hash function computation.
  390.       calc_hash_vector (identifier, xlate_first, xlate_last, second_to_last);
  391.   
  392.       hash_value := (xlate_first + xlate_last + (2 * second_to_last)
  393.             + id_length);
  394.  
  395.       --  Look up the reserved word value in the hash table to see         --|
  396.       --  if a reserved word was found.  Report the status to the         --|
  397.       --  calling program and then exit this function.                 --|
  398.   
  399.       RETURN ( identifier_matches_hash (hash_value, identifier, id_length) );
  400.   
  401.  
  402.   END is_Ada_reserved_word;
  403.  
  404. END reserve_word_hash_pkg;
  405. --::::::::::
  406. --read_me.test
  407. --::::::::::
  408.     The compilation order for the useful package is:
  409.  
  410. reserve_word_hash_pkg_.ada    -- The package specifications
  411. reserve_word_hash_pkg.ada    -- The package body
  412.  
  413.  
  414.  
  415.     To run the demonstration tests, the compilation order is:
  416.  
  417. reserve_word_hash_pkg_.ada    -- The package specifications
  418. reserve_word_hash_pkg.ada    -- The package body
  419. driver.ada            -- The test driver.
  420.  
  421. There are three files which are used by the supplied test driver.  They
  422. are:
  423.  
  424. test_go.txt        -- Contains Ada reserved words.
  425. test_nogo.txt        -- Contains identifiers which are NOT Ada reserved words
  426. test_mixed.txt        -- A mixture of reserved words and just plain junk.
  427.  
  428. Note the supplied test driver will never send the is_ada_reserved_word
  429. function a string which contains a blank. (This is due to the way
  430. the driver parses the input stream.)
  431.  
  432. These programs were developed on DEC Ada, v1.0-7.  The machines used were
  433. 780, 750 and 8600; several were clustered.  No other compiler was used
  434. as a cross-check.
  435.  
  436.  
  437.                         MJG
  438.                         1/29/86.
  439. --::::::::::
  440. --driver.ada
  441. --::::::::::
  442. -- This driver routine tests the  RESERVE_WORD_HASH_PKG.
  443.  
  444. -- The approach is to pass sample words through it; the words come
  445. -- from disk files.
  446.  
  447. -- This is the result of a special Johns Hopkins University student project.
  448.  
  449. -- The design of the implemented algorithm is given in package
  450. -- RESERVE_WORD_HASH_PKG.  The package specification provides a function
  451. -- called IS_ADA_RESERVED_WORD which takes the token (which is an
  452. -- unconstrained string variable), the 
  453. -- length of the token (in token characters) as input, and returns a 
  454. -- boolean TRUE or FALSE depending if the token hashes properly into the 
  455. -- reserved word hash table.  The package specification also makes a few types 
  456. -- available for use.  All others are placed in the package body so 
  457. -- they are not readily accessable.
  458. --
  459. --
  460. -- This program was written by Jerry Kashtan on 11/16/85.  
  461. -- It was modified by Mars Gralia on 1/24/86: modularized and blank tests.
  462. -- Modified by Mars Gralia on 1/29/86: this header block.
  463. -- Modified by Mars Gralia on 1/29/86: changed input to text_io.
  464.  
  465.  
  466.  
  467. WITH RESERVE_WORD_HASH_PKG, TEXT_IO;
  468. USE TEXT_IO;
  469.  
  470. PROCEDURE driver IS
  471.  
  472.  
  473.   PACKAGE INT_IO IS NEW TEXT_IO.INTEGER_IO (INTEGER);
  474.   USE INT_IO;
  475.  
  476.   TYPE input_data_file_types IS (Ada_reserved_words,
  477.              non_Ada_reserved_words, mixed_words);
  478.  
  479.   data_file : TEXT_IO.FILE_TYPE;
  480.  
  481.   max_line_length          : CONSTANT INTEGER := 80;
  482.   max_page_size            : CONSTANT INTEGER := 50;
  483.   
  484.   got_length               : INTEGER RANGE 1..max_line_length;
  485.   pos                      : INTEGER RANGE 1..max_line_length;
  486.   line_count               : INTEGER RANGE 1..max_page_size;
  487.   proposed_reserved_word   : reserve_word_hash_pkg.id_type(1..max_line_length);
  488.   proposed_res_word_length : reserve_word_hash_pkg.id_length_type;
  489.  
  490.   PROCEDURE write_banner IS
  491.  
  492.     BEGIN   -- write_banner procedure
  493.       PUT_LINE ("KEYWORD SEARCH PROGRAM USING PERFECT HASH FUNCTION ALGORITHM");
  494.       PUT_LINE ("    PROGRAM ALGORITHM ADOPTED FROM ADA LETTERS JOURNAL");
  495.       PUT_LINE (" ");
  496.       PUT_LINE ("                    Program Output");
  497.       PUT_LINE (" ");
  498.  
  499.   END write_banner;
  500.  
  501.  
  502.   PROCEDURE special_new_line
  503.     (
  504.     line_count : IN OUT INTEGER
  505.     ) IS
  506.       BEGIN    -- special_new_line
  507.     PUT_LINE (" ");
  508.     line_count := line_count + 1;
  509.  
  510.     IF line_count >= max_page_size THEN
  511.       line_count := 1;
  512.       NEW_PAGE;
  513.       write_banner;
  514.     END IF;
  515.   END special_new_line;
  516.  
  517.  
  518.   PROCEDURE clear_token_string IS
  519.   -- Clear the token string variable by loading blanks.
  520.     BEGIN   -- clear_token_string
  521.         FOR i IN 1..max_line_length LOOP
  522.           proposed_reserved_word (i) := ' ';
  523.         END LOOP;
  524.   END clear_token_string;
  525.  
  526.  
  527.   PROCEDURE test_one
  528.     (
  529.     proposed_reserved_word   : IN reserve_word_hash_pkg.id_type;
  530.     proposed_res_word_length : IN reserve_word_hash_pkg.id_length_type;
  531.     line_count               : IN OUT INTEGER
  532.     ) IS
  533.  
  534.     BEGIN   -- test_one
  535.     PUT (" token => ");
  536.     PUT (proposed_reserved_word(1..proposed_res_word_length));
  537.     SET_COL (35);
  538.  
  539.     IF reserve_word_hash_pkg.is_Ada_reserved_word 
  540.         (proposed_reserved_word,
  541.         proposed_res_word_length) THEN
  542.       PUT (" is an Ada reserved word");
  543.     ELSE 
  544.       PUT (" is not an Ada reserved word");
  545.     END IF;
  546.     
  547.     special_new_line (line_count);
  548.  
  549.   END test_one;
  550.  
  551.   BEGIN   -- driver procedure
  552.  
  553.     FOR current_file IN input_data_file_types LOOP
  554.  
  555.       CASE current_file IS
  556.         WHEN Ada_reserved_words =>
  557.                             TEXT_IO.OPEN (data_file, IN_FILE, "test_go.txt");
  558.                             TEXT_IO.SET_INPUT (data_file);
  559.         WHEN non_Ada_reserved_words =>
  560.                             TEXT_IO.OPEN (data_file, IN_FILE, "test_nogo.txt");
  561.                             TEXT_IO.SET_INPUT (data_file);
  562.         WHEN mixed_words =>
  563.                             TEXT_IO.OPEN (data_file, IN_FILE, "test_mixed.txt");
  564.                             TEXT_IO.SET_INPUT (data_file);
  565.       END CASE;
  566.  
  567.       NEW_PAGE;
  568.       write_banner;
  569.       line_count := 1;
  570.  
  571.       WHILE NOT END_OF_FILE LOOP
  572.  
  573.     clear_token_string;
  574.  
  575.         TEXT_IO.GET_LINE (proposed_reserved_word, got_length);
  576.  
  577.         -- Search token string variable for first blank character.  
  578.         -- The blank character will signal the end of the meaningful 
  579.         -- token substring.
  580.     IF (got_length > 0) THEN
  581.         pos := 1;
  582.         WHILE proposed_reserved_word(pos) /= ' ' LOOP
  583.           exit when pos = max_line_length;
  584.           pos := pos + 1;
  585.         END LOOP;
  586.         IF (pos <= max_line_length) THEN
  587.         pos := pos - 1;
  588.  
  589.         proposed_res_word_length := pos;
  590.  
  591.         test_one (
  592.             proposed_reserved_word(1..proposed_res_word_length),
  593.             proposed_res_word_length,
  594.             line_count);
  595.         END IF;
  596.     END IF;
  597.  
  598.       END LOOP;
  599.  
  600.       TEXT_IO.CLOSE (data_file);
  601.  
  602.     END LOOP;   -- Go back and open another data file.
  603.  
  604.     -- Try some strings of blanks
  605.     clear_token_string;
  606.     FOR j IN 0..max_line_length LOOP
  607.       IF (reserve_word_hash_pkg.is_Ada_reserved_word
  608.         (proposed_reserved_word, j ) )THEN
  609.     PUT (" ERROR: string of");
  610.     PUT (j);
  611.     PUT (" blanks is a reserved word!");
  612.     PUT (" ");
  613.         special_new_line (line_count);
  614.       END IF;
  615.    END LOOP;    
  616.     
  617.       
  618.  
  619. END DRIVER;
  620.     
  621. --::::::::::
  622. --test_go.txt
  623. --::::::::::
  624. ABORT
  625. ABS
  626. ACCEPT
  627. access
  628. all
  629. and
  630. ArRaY
  631. At
  632. BEGin
  633. BodY
  634. casE
  635. CONSTANt
  636. declare
  637. delay
  638. delta
  639. digits
  640. do
  641. else
  642. elsif
  643. end
  644. ENTRY
  645. EXCEPTION
  646. EXIT
  647. FOR
  648. FUNCTION
  649. GENERIC
  650. GOTO
  651. IF
  652. IN
  653. IS
  654. LIMITED
  655. loop
  656. mod
  657. new
  658. not
  659. null
  660. of
  661. or
  662. others
  663. Out
  664. Package
  665. Pragma
  666. Private
  667. Procedure
  668. Raise
  669. Range
  670. Record
  671. Rem
  672. renameS
  673. returN
  674. reVERse
  675. select
  676. SEPARATE
  677. SUBTYPE
  678. TASK
  679. TERMINATE
  680. THEN
  681. TYPE
  682. USE
  683. when
  684. while
  685. with
  686. xor
  687. --::::::::::
  688. --test_nogo.txt
  689. --::::::::::
  690. Jerry
  691. Kashtan
  692. new_values
  693. X01_1
  694. Ada__keyword
  695. Ada_
  696. Identifier_1234_5678_90
  697. T
  698. z
  699. off
  700. often
  701. last_word_in_this_file
  702. --::::::::::
  703. --test_mixed.txt
  704. --::::::::::
  705. ABORT
  706. Jerry
  707. Kashtan
  708. Procedure
  709. FIND_identifier
  710. OR
  711. Private
  712. NeXt_ScReEn
  713. a3b
  714. a.b
  715. a
  716. 3
  717. a-b
  718. package
  719. pa..age
  720. ------
  721.  
  722.