:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: : method PHONECODE: Print word combinations for a list of phone numbers. entry Code Path, &Path of a code word dictionary file Phone Path :Path of a phone number file local Dictionary Map..heap..string, &Dictionary map number -> {code, ...} Digit string, &Digits in a phone number Line word, &Current line in the phone number file Partial Bit, &A partial encoding was found Phone.Max |= 50 :Maximum phone number width : : Note: The Phonecode program will terminate on input errors. :............................................................................... LOAD.DICTIONARY Dictionary, Code`Value; Read in all code words. assert Dictionary`Size pass Code`Value; The dictionary file is empty. DO Number from Read.Text( Phone`Value ): DO over the phone number file, Line += 1; Current line number. Digit = ""; Begin accumulating digits. assert length( Number ) <= Phone.Max &Phone number is too long. pass "line = " ! form( Line ) DO C in Number: DO over phone number characters, IF C = '0' to '9': IF a decimal digit, Digit != C; Accumulate digits. ELSE: ELSE skipping a non-digit, assert C = '/' | '-' &Invalid phone number. pass "line = " ! form( Line ) - . assert Digit pass Number; A phone number has no digits. ENCODE.PHONE Dictionary, Number, Digit, &Print combinations of words. "", 1, Partial IF Partial = 0: IF no partial encoding, IF length( Digit ) = 1: IF a trivial one digit number, PRINT Number ! ":", Digit; Encode as a digit. ELSE: ELSE multiple digits, ENCODE.PHONE Dictionary, Number, Digit, &Encode with a lead digit. left( Digit ), 2 - . . return