Example of using the Interpreter Pattern in C#. More...
Public Member Functions | |
void | Run () |
Executes the example for the Interpreter Pattern in C#. | |
Private Member Functions | |
string | _TokensToString (int[] tokens) |
Helper method to convert a list of ints to a string representation. | |
Static Private Attributes | |
static int[][] | _sentenceTokenLists |
A list of pre-defined 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. | |
Example of using the Interpreter Pattern in C#.
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 31 of file Interpreter_Exercise.cs.
|
inlineprivate |
Helper method to convert a list of ints to a string representation.
tokens | Array of ints to work with. |
Definition at line 39 of file Interpreter_Exercise.cs.
Referenced by Interpreter_Exercise.Run().
|
inline |
Executes the example for the Interpreter Pattern in C#.
Definition at line 76 of file Interpreter_Exercise.cs.
References Interpreter_Exercise._sentenceTokenLists, Interpreter_Exercise._TokensToString(), and Interpreter_Class.Interpret().
Referenced by Program.Run().
|
staticprivate |
A list of pre-defined 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 63 of file Interpreter_Exercise.cs.
Referenced by Interpreter_Exercise.Run().