pub fn interpreter_exercise() -> Result<(), String>
Expand description

Example of using the “Interpreter” design pattern.

The interpreter is a function that is fed a series of arrays containing integer tokens. Each token represents a single word or punctuation mark. The interpreter converts that array of tokens to an actual sentence by interpreting the meaning of the tokens.

This is a very simple interpreter that handles the first token in a special way and supports punctuation. It is an example of a linear interpreter where tokens can appear in any order (it’s up to the creator of the token list to make sure the outcome makes any sense).

The output shows the token list followed by the sentence produced from the tokens.