Functions | |
str | _TokensToString (list[int] tokens) |
Helper method to convert a list of tokens to a string representation. | |
def | Interpreter_Exercise () |
Example of using the Interpreter Pattern. | |
Variables | |
list | _sentenceTokenLists |
A list of predefined token lists. | |
|
protected |
Helper method to convert a list of tokens to a string representation.
tokens | Array of ints to work with. |
Definition at line 29 of file interpreter_exercise.py.
Referenced by DesignPatternExamples_python.interpreter.interpreter_exercise.Interpreter_Exercise().
def Interpreter_Exercise | ( | void | ) |
Example of using the Interpreter Pattern.
The interpreter is instantiated then 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.
Definition at line 58 of file interpreter_exercise.py.
References DesignPatternExamples_python.interpreter.interpreter_exercise._TokensToString().
|
protected |
A list of predefined token lists.
Each token list represents a single sentence constructed from the 40 most common words in the English language. I don't use all 40 words, though; that would be silly.
Definition at line 14 of file interpreter_exercise.py.