Function design_pattern_examples_rust::interpreter::interpreter_interpreter::interpreter_interpret
source · pub fn interpreter_interpret(token_list: &[usize]) -> String
Expand description
This function is a simple interpreter.
The interpreter takes an array of integer tokens and converts each token into a word or punctuation mark. The interpreter then arranges the words into a space-separated list in a single string. In other words, the tokens are converted into a sentence, with the first word capitalized and no space between the last two “words” under the assumption the last word is actually a punctuation mark.
Interpreter Rules:
- Each token must be in the range of 0 through 39 (maximum number of words known by the interpreter) or must be 100 (‘.’) or 101 (‘?’).
- The word corresponding to the first token is always capitalized.
- A single space appears between each word.
- No space appears between the last two tokens.
Parameters
-
tokenList
List of integer tokens to be interpreted. The list is assumed to be terminated by -1 (EOL).
Returns
Returns a new String containing the result of the interpretation.