1 //  These routines are used for initialization of the lexical analyzer.
  2 //  Last modified on 06/06/74 at 18:25:59 by R F Mabee.
  3 //  Prepared for installation with Version 3.4, R F Mabee.
  4 //  Rewritten in March 1973 to predefine reserved words rather than recognize then algorithmically (old Lookupword).
  5 //  First version installed in Version 2.7, R F Mabee.
  6 
  7 //  Copyright (c) 1974 by Massachusetts Institute of Technology and Honeywell Information Systems, Inc.
  8 
  9 //  General permission is granted to copy and use this program, but not to sell it, provided that the above
 10 //  copyright statement is given.  Contact Information Processing Services, MIT, for further information.
 11 //  Please contact R F Mabee at MIT for information on this program and versions for other machines.
 12 
 13 get "bcpl_lex_head"
 14 
 15 
 16 //  This routine applies a given routine to all the system words and their internal codes.
 17 
 18 let MapSystemwords (MapF) be
 19      $(   MapF ("and", AND_S)
 20 
 21           MapF ("break", BREAK_S); MapF ("be", BE_S); MapF ("begin", SECTBEGIN_S)
 22           MapF ("bit", BIT_S); MapF ("by", BY_S)
 23 
 24           MapF ("case", CASE_S); MapF ("call", CALL_S); MapF ("char", CHAR_S)
 25 
 26           MapF ("do", DO_S); MapF ("default", DEFAULT_S); MapF ("double", DOUBLE_S)
 27 
 28           MapF ("endcase", ENDCASE_S); MapF ("else", OR_S); MapF ("end", SECTEND_S)
 29           MapF ("eqv", EQV_S); MapF ("external", EXTERNAL_S); MapF ("eq", EQ_S)
 30 
 31           MapF ("for", FOR_S); MapF ("false", FALSE_S); MapF ("fixed", FIXED_S)
 32           MapF ("finish", FINISH_S); MapF ("float", FLOAT_S)
 33 
 34           MapF ("goto", GOTO_S); MapF ("ge", GE_S); MapF ("get", GET_S)
 35           MapF ("global", GLOBAL_S); MapF ("gr", GR_S)
 36 
 37           MapF ("if", IF_S); MapF ("ifso", IFSO_S); MapF ("ifnot", IFNOT_S)
 38           MapF ("into", INTO_S)
 39 
 40           MapF ("let", LET_S); MapF ("le", LE_S); MapF ("loop", LOOP_S)
 41           MapF ("logand", LOGAND_S); MapF ("logor", LOGOR_S); MapF ("length", LENGTH_S)
 42           MapF ("list", LIST_S); MapF ("lshift", LSHIFT_S); MapF ("lv", LV_S)
 43           MapF ("ls", LS_S)
 44 
 45           MapF ("manifest", MANIFEST_S); MapF ("main", MAIN_S)
 46 
 47           MapF ("nil", NIL_S); MapF ("not", NOT_S); MapF ("ne", NE_S)
 48           MapF ("neqv", NEQV_S)
 49 
 50           MapF ("or", OR_S); MapF ("offset", OFFSET_S); MapF ("otherwise", OR_S)
 51 
 52           MapF ("pointer", POINTER_S); MapF ("ptr", POINTER_S)
 53 
 54           MapF ("repeatuntil", REPEATUNTIL_S); MapF ("resultis", RESULTIS_S); MapF ("rem", REM_S)
 55           MapF ("repeatwhile", REPEATWHILE_S); MapF ("rshift", RSHIFT_S); MapF ("return", RETURN_S)
 56           MapF ("repeat", REPEAT_S); MapF ("rv", RV_S); MapF ("rep", REP_S)
 57 
 58           MapF ("static", STATIC_S); MapF ("structure", STRUCTURE_S); MapF ("switchon", SWITCHON_S)
 59           MapF ("string", STRING_S); MapF ("step", BY_S)
 60 
 61           MapF ("then", DO_S); MapF ("table", TABLE_S); MapF ("test", TEST_S)
 62           MapF ("true", TRUE_S); MapF ("type", TYPE_S); MapF ("to", TO_S)
 63 
 64           MapF ("unless", UNLESS_S); MapF ("until", UNTIL_S)
 65 
 66           MapF ("valof", VALOF_S); MapF ("vec", VEC_S)
 67 
 68           MapF ("while", WHILE_S)
 69      $)
 70 
 71 //  Initialize the dictionary to contain all reserved words for faster lookup later.
 72 
 73 let LoadDictionary () be
 74      $(   MapSystemwords (DefineSystemword)
 75           if UpperCase do MapSystemwords (DefineUppercaseSystemword)
 76      $)
 77 and DefineSystemword (Word, Symbol) be
 78      $(   Unpackstring (Word, V)
 79           EnterIntoDictionary (V, Symbol)
 80      $)
 81 and DefineUppercaseSystemword (Word, Symbol) be
 82      $(   Unpackstring (Word, V)
 83           for i = 1 to V!0 do V!i := MakeUpperCase (V!i)
 84           EnterIntoDictionary (V, Symbol)
 85      $)
 86 and MakeUpperCase (c) = valof switchon c into               //  Map lower case to upper for any character set.
 87      $(   case 'a': resultis 'A'
 88           case 'b': resultis 'B'
 89           case 'c': resultis 'C'
 90           case 'd': resultis 'D'
 91           case 'e': resultis 'E'
 92           case 'f': resultis 'F'
 93           case 'g': resultis 'G'
 94           case 'h': resultis 'H'
 95           case 'i': resultis 'I'
 96           case 'j': resultis 'J'
 97           case 'k': resultis 'K'
 98           case 'l': resultis 'L'
 99           case 'm': resultis 'M'
100           case 'n': resultis 'N'
101           case 'o': resultis 'O'
102           case 'p': resultis 'P'
103           case 'q': resultis 'Q'
104           case 'r': resultis 'R'
105           case 's': resultis 'S'
106           case 't': resultis 'T'
107           case 'u': resultis 'U'
108           case 'v': resultis 'V'
109           case 'w': resultis 'W'
110           case 'x': resultis 'X'
111           case 'y': resultis 'Y'
112           case 'z': resultis 'Z'
113           default:  resultis c          //  All others map into themselves.
114      $)